Hi William
I have studied the example you have posted and tried to change it to my situation
I now have code that works sometimes.
Sometimes Access doesn't change to the new selection and returns the previous one (I made sure that the "previous one" was closed.
And sometimes I get run time error 3075:
Syntax error (missing operator) in query expression '(([CountryID] = *))'.
Especially the first time I open the form and try to make a selection this error occurs
(As you can see I've managed to add the "All" to the listbox, thanks to your suggestions.)
This example is with "*", it also appears when I choose other countries.
The code I've made is as follows:
'General declaration
Option Compare Database
Dim vWhereCountry As Variant
Determining which countries should be included in the report
CODE
Private Sub lstCountries_AfterUpdate()
On Error GoTo AfterUpdate_Error
Dim varItem As Variant
Dim strTempItem As String
For Each varItem In Me.ActiveControl.ItemsSelected
strTempItem = strTempItem & " [CountryID] = " & Me.ActiveControl.ItemData(varItem) & " or "
Next
strTempItem = "(" & Left(strTempItem, Len(strTempItem) - 4) & ")"
vWhereCountry = Null
vWhereCountry = strTempItem
AfterUpdate_Error_Exit:
Exit Sub
AfterUpdate_Error:
If Err.Number = 5 Then
vWhereCountry = Null
Resume AfterUpdate_Error_Exit
Else
MsgBox Err.Number & " - " & Err.Description
Resume AfterUpdate_Error_Exit
End If
End Sub
************************
' Opening report with button
Private Sub cmdButton_Click()
Dim vWhere As Variant
Dim strDocName As String
strDocName = "RapRanglijsten"
vWhere = Null
vWhere = vWhere & vWhereCountry
DoCmd.OpenReport strDocName, acPreview, , vWhere
End Sub
Can you tell from this if there is too much code, or if code is missing?
Hope to hear from yoy
Thanks in advance
Hein
Edited by: Hein on Tue Oct 9 15:07:15 EDT 2007.