Hi,
I am working on a simple database where i would like the user to select records from a multiple selection list box and then based on what the user had chosen a report displayed for just those records.
I have some code from a sample database but i cant get it to work.
I have 2 fields in a table called ID NO and Name
I have a form called Sounds
Everytime i press the button i get the following error message
***********************************************
Runtime error "3075"
Syntax error (Missing operator ) In query expression '(ID n)'
***********************************************
I have copied and pasted the code below:
'Run a report displaying only the records chosen
'by the user in the form's listbox.
Dim v As Variant
Dim Frm As Form
Dim ctl As Control
Dim theId As Long
Dim WhereCrit As String
'If nothing is selected, notify user...
If Me.LstFindings.ItemsSelected.Count = 0 Then
MsgBox "Please select a supplier or two.", vbExclamation, "No Supplier Selected"
'and then scram.
Exit Sub
End If
'Assign form and control to object variables.
Set Frm = Forms!Sounds
Set ctl = Frm!LstFindings
'Begin building Where string.
WhereCrit = "ID no = "
'Add each selected item to the WHERE string.
For Each v In ctl.ItemsSelected
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'The first column in the list, holding SupplierID, is hidden.
'See the list's "Column Widths" and "Column Count" properties in
'its property dialog and look up the terms in Help for more info.
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Coordinates: 1st column (0); row v --
'where v changes for each round of the loop.
theId = ctl.Column(0, v)
WhereCrit = WhereCrit & theId & " OR ID no = "
Next v
'Loop ends; selected items are now accounted for...
'Test: Uncomment the next line to print the Where string to the Immediate window.
'Debug.Print WhereCrit
'Clean-up the Where string by removing the trailing text.
WhereCrit = Left(WhereCrit, Len(WhereCrit) - 17)
'Test: Uncomment the next line to print the Where string to the Immediate window.
'Debug.Print WhereCrit
'Open the suppliers report using the Where clause to filter it.
DoCmd.OpenReport "report", acViewPreview, , WhereCrit
End Sub
Any help would be much appreciated.
Thanks in Advance
I am working on a simple database where i would like the user to select records from a multiple selection list box and then based on what the user had chosen a report displayed for just those records.
I have some code from a sample database but i cant get it to work.
I have 2 fields in a table called ID NO and Name
I have a form called Sounds
Everytime i press the button i get the following error message
***********************************************
Runtime error "3075"
Syntax error (Missing operator ) In query expression '(ID n)'
***********************************************
I have copied and pasted the code below:
'Run a report displaying only the records chosen
'by the user in the form's listbox.
Dim v As Variant
Dim Frm As Form
Dim ctl As Control
Dim theId As Long
Dim WhereCrit As String
'If nothing is selected, notify user...
If Me.LstFindings.ItemsSelected.Count = 0 Then
MsgBox "Please select a supplier or two.", vbExclamation, "No Supplier Selected"
'and then scram.
Exit Sub
End If
'Assign form and control to object variables.
Set Frm = Forms!Sounds
Set ctl = Frm!LstFindings
'Begin building Where string.
WhereCrit = "ID no = "
'Add each selected item to the WHERE string.
For Each v In ctl.ItemsSelected
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'The first column in the list, holding SupplierID, is hidden.
'See the list's "Column Widths" and "Column Count" properties in
'its property dialog and look up the terms in Help for more info.
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Coordinates: 1st column (0); row v --
'where v changes for each round of the loop.
theId = ctl.Column(0, v)
WhereCrit = WhereCrit & theId & " OR ID no = "
Next v
'Loop ends; selected items are now accounted for...
'Test: Uncomment the next line to print the Where string to the Immediate window.
'Debug.Print WhereCrit
'Clean-up the Where string by removing the trailing text.
WhereCrit = Left(WhereCrit, Len(WhereCrit) - 17)
'Test: Uncomment the next line to print the Where string to the Immediate window.
'Debug.Print WhereCrit
'Open the suppliers report using the Where clause to filter it.
DoCmd.OpenReport "report", acViewPreview, , WhereCrit
End Sub
Any help would be much appreciated.
Thanks in Advance