J
Julia
Hi,
I don't have a lot of experience with Access. I would like to open records
based on a selection in a list box and then make a report. This can also
happen in one step.
I have records for projects. Each project has a product, and one product can
be in many different projects.
I have tried Allen Brown's method (for reports) and one from the Microsoft
web page in which you use the Filter property of a form, but I cannot seem to
get either one to work. I have gotten further with the Microsoft option, but
I get an error message "You cancelled the previous operation". This method
also is not very clear about where to put the Command to open the form based
on the filter criteria. I can see from the code that my selection is getting
through but for some reason I am having difficulties opening the form based
on the filter criteria. This could be because I am using the wrong syntax to
specify the filter.
Can anyone help me?
This is the code I have:
Private Sub Command2_Click()
Dim Criteria As String
Dim i As Variant
'Build criteria string from selected items in list box
Criteria = ""
For Each i In Me![List0].ItemsSelected
If Criteria <> "" Then
Criteria = Criteria & " OR "
End If
Criteria = Criteria & "[PrimKey]='" _
& Me![List0].ItemData(i) & "'"
Next i
'Filter the form using selected items in the list box
Me.Filter = Criteria
Me.FilterOn = True
DoCmd.OpenForm "MainForm", acNormal, Criteria
End Sub
I don't have a lot of experience with Access. I would like to open records
based on a selection in a list box and then make a report. This can also
happen in one step.
I have records for projects. Each project has a product, and one product can
be in many different projects.
I have tried Allen Brown's method (for reports) and one from the Microsoft
web page in which you use the Filter property of a form, but I cannot seem to
get either one to work. I have gotten further with the Microsoft option, but
I get an error message "You cancelled the previous operation". This method
also is not very clear about where to put the Command to open the form based
on the filter criteria. I can see from the code that my selection is getting
through but for some reason I am having difficulties opening the form based
on the filter criteria. This could be because I am using the wrong syntax to
specify the filter.
Can anyone help me?
This is the code I have:
Private Sub Command2_Click()
Dim Criteria As String
Dim i As Variant
'Build criteria string from selected items in list box
Criteria = ""
For Each i In Me![List0].ItemsSelected
If Criteria <> "" Then
Criteria = Criteria & " OR "
End If
Criteria = Criteria & "[PrimKey]='" _
& Me![List0].ItemData(i) & "'"
Next i
'Filter the form using selected items in the list box
Me.Filter = Criteria
Me.FilterOn = True
DoCmd.OpenForm "MainForm", acNormal, Criteria
End Sub