Below is the code I am using to pass a multi-variable string to a report. When I run the code I get the message in the "Parameter.jpg" attachment. I added "msgbox.jpg" attachment to show what the string value is. The NameStr is passing fine, but the dateStr is not. Both are text fields in the database. If I type "2012 Spring" (with no quotes) in the Parameter box the variable passes fine and report pops up filtered correctly. Not sure what to change, any help is much appreciated.
Private Sub bSubmit_Click()
Dim NameStr As String, dateStr As String
Dim SQLStr As String
Dim ListCounter As Integer
Dim AnItem As Variant
Dim strReport As String
strReport = "rIndividualReport"
For Each AnItem In Me.lName.ItemsSelected
If Not IsNull(AnItem) Then
NameStr = NameStr & "'" & Me.lName.ItemData(AnItem) & "',"
End If
Next AnItem
If Len(NameStr) = 0 Then
MsgBox "You did not select a Customer" _
, vbExclamation, "Nothing to find!"
Exit Sub
Else
NameStr = Left(NameStr, Len(NameStr) - 1)
End If
For Each AnItem In Me.lDate.ItemsSelected
If Not IsNull(AnItem) Then
dateStr = dateStr & "'" & Me.lDate.ItemData(AnItem) & "',"
End If
Next AnItem
If Len(dateStr) = 0 Then
MsgBox "You did not select an IOR Date" _
, vbExclamation, "Nothing to find!"
Exit Sub
Else
dateStr = Left(dateStr, Len(dateStr) - 1)
End If
SQLStr = "SELECT tIORData.[Name], tIORData.[Review Date] " & _
"FROM tIORData " & _
"WHERE tIORData.[Name] IN(" & NameStr & ") and tIORData.[Review Date] IN(" & dateStr & ")"
MsgBox SQLStr
DoCmd.OpenReport strReport, acPreview, filtername:=SQLStr
DoCmd.Close acForm, "fLoadCustomerReport"
End Sub
Private Sub bSubmit_Click()
Dim NameStr As String, dateStr As String
Dim SQLStr As String
Dim ListCounter As Integer
Dim AnItem As Variant
Dim strReport As String
strReport = "rIndividualReport"
For Each AnItem In Me.lName.ItemsSelected
If Not IsNull(AnItem) Then
NameStr = NameStr & "'" & Me.lName.ItemData(AnItem) & "',"
End If
Next AnItem
If Len(NameStr) = 0 Then
MsgBox "You did not select a Customer" _
, vbExclamation, "Nothing to find!"
Exit Sub
Else
NameStr = Left(NameStr, Len(NameStr) - 1)
End If
For Each AnItem In Me.lDate.ItemsSelected
If Not IsNull(AnItem) Then
dateStr = dateStr & "'" & Me.lDate.ItemData(AnItem) & "',"
End If
Next AnItem
If Len(dateStr) = 0 Then
MsgBox "You did not select an IOR Date" _
, vbExclamation, "Nothing to find!"
Exit Sub
Else
dateStr = Left(dateStr, Len(dateStr) - 1)
End If
SQLStr = "SELECT tIORData.[Name], tIORData.[Review Date] " & _
"FROM tIORData " & _
"WHERE tIORData.[Name] IN(" & NameStr & ") and tIORData.[Review Date] IN(" & dateStr & ")"
MsgBox SQLStr
DoCmd.OpenReport strReport, acPreview, filtername:=SQLStr
DoCmd.Close acForm, "fLoadCustomerReport"
End Sub
Attachments
Last edited: