listbox search forms

potts

Registered User.
Local time
Today, 12:58
Joined
Jul 24, 2002
Messages
87
I posted this question on one of the other forums, but haven't had much luck - was wondering if anyone here had any ideas.

I have build a form containing a multi-select list box and a command button. Attached to the on click event of the command button is the following code:

Dim strWhere As String, varItem As Varient
If Me.lstProcedures.ItemsSelected.Count = 0 Then
Exit Sub
End If

For Each varItem In Me.lstProcedures.ItemsSelected
strWhere = strWhere & Chr$ (34) & Me.lstProcedures.Column(0, varItem) & Chr$ (34) & ","
Next varItem
strWhere = Left$ (strWhere, Len(strWhere) - 1)
gstrWhereProcedure = "[ProcedureID] In (" & strWhere & ")"
Do.Cmd.OpenForm FormName:="frmInputProcedures", WhereCondition:=gstrWhereProcedure
End Sub

the form to be opened is called frmInputProcedures
the list box is called lstProcedures
the bound column of the listbox query is the first column and contains the ProcedureID that identifies the fields in frmInputProcedures.
the frmInputProcedures form is a tabular form

My problem is that when the command button is clicked, a form appears asking me to enter a parameter value for the ProcedureID - I don't want this to happen.

does anyone know how I might fix this problem? Or does any one have a better system for filtering values in one form based on the values filtered in a list box on another form?
 
Use debug.Print to get and check the value in gstrWhereProcedure after the loop. I'd like to see what you are getting looks like.
 
You typed the code in, right? Typo, strWhere with gstrWhere..., DoCmd. with Do.Cmd...!!

Change Chr$(34) to Chr$(39) if the ProcedureID field is Text, or remove it out if number.

Or is the ProcedureID field exist? If not, you will get the prompt.

HTH.
 
Last edited:
got it sorted. had the wrong Id typed in - idiot!!!

Still cant say I really understand all the code though
 

Users who are viewing this thread

Back
Top Bottom