stukanewss
MIS
In a form I have a SQL string that is dynamically created, and I'm trying to pass that to the record source of a report. The procedure to create the string resides in a private event button click procedure. I have set up a public variable in another module and I can not pass that value to the report recordsource property. Any suggestions?
Here is the code for the string creation. The string creation part of this works:
Private Sub Pending_Click()
Dim icounter As Integer
Dim squery As String
Dim sselected As String
For icounter = 0 To List0.ListCount - 1
If List0.Selected(icounter) Then
sselected = sselected & IIf(Len(sselected) = 0, "", "," & Chr(39) & List0.Column(0, icounter) & Chr(39)
End If
Next icounter
MsgBox (sselected)
If Len(sselected) > 0 Then
squery = "SELECT Local Opty.Account, Local Opty.Author, Local Opty.Title, Local Opty.Edition, Local Opty.Units, Local Opty.Revenue, Local Opty.Status, Local Opty.[Decision Date], Local Opty.Discipline, Local Opty.Course, Local Opty.Type, Local Opty.[Sales Rep], Local Opty.[Semester of Use], Local Opty.ISBN, Count(*) AS [Count Of Opty], Count(*) AS [Count of SalesRep] FROM Opty GROUP BY Local Opty.Account, Local Opty.Author, Local Opty.Title, Local Opty.Edition, Local Opty.Units, Local Opty.Revenue, Local Opty.Status, Local Opty.[Decision Date], Local Opty.Discipline, Local Opty.Course, Local Opty.Type, Local Opty.[Sales Rep], Local Opty.[Semester of Use], Local Opty.ISBN HAVING (((Local Opty.Status)='Pending - High' Or (Local Opty.Status)='Pending - Low' Or (Local Opty.Status)='Pending - Medium') AND ((Local Opty.[Sales Rep]) In ( " & sselected & "));"
Else
squery = "SELECT Local Opty.Account, Local Opty.Author, Local Opty.Title, Local Opty.Edition, Local Opty.Units, Local Opty.Revenue, Local Opty.Status, Local Opty.[Decision Date], Local Opty.Discipline, Local Opty.Course, Local Opty.Type, Local Opty.[Sales Rep], Local Opty.[Semester of Use], Local Opty.ISBN, Count(*) AS [Count Of Opty], Count(*) AS [Count of SalesRep] FROM Opty GROUP BY Local Opty.Account, Local Opty.Author, Local Opty.Title, Local Opty.Edition, Local Opty.Units, Local Opty.Revenue, Local Opty.Status, Local Opty.[Decision Date], Local Opty.Discipline, Local Opty.Course, Local Opty.Type, Local Opty.[Sales Rep], Local Opty.[Semester of Use], Local Opty.ISBN HAVING (((Local Opty.Status)='Pending - High' Or (Local Opty.Status)='Pending - Low' Or (Local Opty.Status)='Pending - Medium');"
End If
On Error Resume Next
rcdsrce = squery
DoCmd.OpenReport "Rep Pending", acViewPreview
End Sub
Here is the Public variable I have created in a separate module:
Option Compare Database
Dim rcdsrce As String
Here is the On Open Event procedure for the report:
Option Compare Database
Private Sub Report_Open(Cancel As Integer)
Me.RecordSource = rcdsrce
End Sub
Here is the code for the string creation. The string creation part of this works:
Private Sub Pending_Click()
Dim icounter As Integer
Dim squery As String
Dim sselected As String
For icounter = 0 To List0.ListCount - 1
If List0.Selected(icounter) Then
sselected = sselected & IIf(Len(sselected) = 0, "", "," & Chr(39) & List0.Column(0, icounter) & Chr(39)
End If
Next icounter
MsgBox (sselected)
If Len(sselected) > 0 Then
squery = "SELECT Local Opty.Account, Local Opty.Author, Local Opty.Title, Local Opty.Edition, Local Opty.Units, Local Opty.Revenue, Local Opty.Status, Local Opty.[Decision Date], Local Opty.Discipline, Local Opty.Course, Local Opty.Type, Local Opty.[Sales Rep], Local Opty.[Semester of Use], Local Opty.ISBN, Count(*) AS [Count Of Opty], Count(*) AS [Count of SalesRep] FROM Opty GROUP BY Local Opty.Account, Local Opty.Author, Local Opty.Title, Local Opty.Edition, Local Opty.Units, Local Opty.Revenue, Local Opty.Status, Local Opty.[Decision Date], Local Opty.Discipline, Local Opty.Course, Local Opty.Type, Local Opty.[Sales Rep], Local Opty.[Semester of Use], Local Opty.ISBN HAVING (((Local Opty.Status)='Pending - High' Or (Local Opty.Status)='Pending - Low' Or (Local Opty.Status)='Pending - Medium') AND ((Local Opty.[Sales Rep]) In ( " & sselected & "));"
Else
squery = "SELECT Local Opty.Account, Local Opty.Author, Local Opty.Title, Local Opty.Edition, Local Opty.Units, Local Opty.Revenue, Local Opty.Status, Local Opty.[Decision Date], Local Opty.Discipline, Local Opty.Course, Local Opty.Type, Local Opty.[Sales Rep], Local Opty.[Semester of Use], Local Opty.ISBN, Count(*) AS [Count Of Opty], Count(*) AS [Count of SalesRep] FROM Opty GROUP BY Local Opty.Account, Local Opty.Author, Local Opty.Title, Local Opty.Edition, Local Opty.Units, Local Opty.Revenue, Local Opty.Status, Local Opty.[Decision Date], Local Opty.Discipline, Local Opty.Course, Local Opty.Type, Local Opty.[Sales Rep], Local Opty.[Semester of Use], Local Opty.ISBN HAVING (((Local Opty.Status)='Pending - High' Or (Local Opty.Status)='Pending - Low' Or (Local Opty.Status)='Pending - Medium');"
End If
On Error Resume Next
rcdsrce = squery
DoCmd.OpenReport "Rep Pending", acViewPreview
End Sub
Here is the Public variable I have created in a separate module:
Option Compare Database
Dim rcdsrce As String
Here is the On Open Event procedure for the report:
Option Compare Database
Private Sub Report_Open(Cancel As Integer)
Me.RecordSource = rcdsrce
End Sub