X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Reply to this topicStart new topic
> Using a Multi-Select Listbox As Criteria for a Form or Report    
Jerry Dennison
post May 30 2002, 08:33 PM

Head Wizard
Posts: 14,857
Joined: 31-January 00
From: South Carolina, USA

You may use the following to allow a user to select multiple items from a multiselect listbox and pass this as criteria to a form or report. This is a two step process. Add a hidden unbound text box to your form to "capture" the criteria. Add this code to the AfterUpdate of the multiselect listbox (make sure you substitute your actual control names for the placeholders given, you may also need to change the single quote delimiters to '#'):
Private Sub List0_AfterUpdate()
Dim varItem As Variant
Dim txtTemp As String
Dim txtCriteria As String
txtCriteria = "[CriteriaFieldName] = "
For Each varItem In Me.List0.ItemsSelected
txtTemp = txtTemp & txtCriteria & "'" & Me.List0.ItemData(varItem) & "'" & " Or "
If Len(txtTemp) > 0 Then
txtTemp = Left(txtTemp, Len(txtTemp) - 4)
End If
Me.HiddenTextboxName = txtTemp
End Sub
Then pass the textbox itself to the form or report you wish to open by placing the following in the OnClick event of the button that opens the form or report:
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "FormName"

stLinkCriteria = Me![HiddenTextBoxName]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Go to the top of the page

Custom Search

RSSSearch   Top   Lo-Fi    16th June 2019 - 01:45 PM