Hi everyone,
I am having trouble with some coding since a long time.
I have 2 listbxes and i select a place name from one list bx and transfer it to another listbox. The i click a cd button to open a report. I want to view only the records for those names which are present in the 2nd listbox. How do i do this?
I have attached a sample dB ... getting an error... type mismatch..
the code is like this:
Set db = CurrentDb()
Set qdf = db.QueryDefs("QueryList")
' Loop through the selected items in the list box and build a text string
'aSelected = mmp.SelectedItems
If Me.lstSelected.ColumnCount > 0 Then
For Each vItem In Me.lstSelected.ItemData(vItem)
strCriteria = strCriteria & "qryInfo.Group_name = " & Chr(34) _
& Me!lstSelected.ItemData(vItem) & Chr(34) & "OR "
Next vItem
strCriteria = Left(strCriteria, Len(strCriteria) - 3)
Else
strCriteria = "qryInfo.Group_name Like '*'"
End If
' Build the new SQL statement incorporating the string
strSQL = "SELECT * FROM qryInfo " & _
"WHERE " & strCriteria & ";"
' Apply the new SQL statement to the query
qdf.SQL = strSQL
' Open the query
DoCmd.OpenQuery "QueryList"
DoCmd.OpenReport "Labels qryInfo1", acViewPreview, , strCriteria, acWindowNormal
' Empty the memory
Set db = Nothing
Set qdf = Nothing
Can you tell me where I am going wrong?
Thanks for your help !
dB
I am having trouble with some coding since a long time.
I have 2 listbxes and i select a place name from one list bx and transfer it to another listbox. The i click a cd button to open a report. I want to view only the records for those names which are present in the 2nd listbox. How do i do this?
I have attached a sample dB ... getting an error... type mismatch..
the code is like this:
Set db = CurrentDb()
Set qdf = db.QueryDefs("QueryList")
' Loop through the selected items in the list box and build a text string
'aSelected = mmp.SelectedItems
If Me.lstSelected.ColumnCount > 0 Then
For Each vItem In Me.lstSelected.ItemData(vItem)
strCriteria = strCriteria & "qryInfo.Group_name = " & Chr(34) _
& Me!lstSelected.ItemData(vItem) & Chr(34) & "OR "
Next vItem
strCriteria = Left(strCriteria, Len(strCriteria) - 3)
Else
strCriteria = "qryInfo.Group_name Like '*'"
End If
' Build the new SQL statement incorporating the string
strSQL = "SELECT * FROM qryInfo " & _
"WHERE " & strCriteria & ";"
' Apply the new SQL statement to the query
qdf.SQL = strSQL
' Open the query
DoCmd.OpenQuery "QueryList"
DoCmd.OpenReport "Labels qryInfo1", acViewPreview, , strCriteria, acWindowNormal
' Empty the memory
Set db = Nothing
Set qdf = Nothing
Can you tell me where I am going wrong?
Thanks for your help !
dB
Attachments
Last edited: