Using a list in an a form to define a WHERE clause

  • Thread starter PelleritoConsultants
  • Start date
P

PelleritoConsultants

I am learning how to use a list box contained in a form as part of a WHERE
clause;

Is this the right code? When I click on the command button and select the
itmes I want used within my WHERE clause I only get blank records in the
report generated by the command.

Private Sub btn_cmd8_gjl_Click()
On Error GoTo Err_btn_cmd8_gjl_Click

Dim stDocName As String

stDocName = "rptDEPTxLocation-Lysse"
DoCmd.OpenReport stDocName, acPreview, , "[Location] = '" & lst1_gjl & "'"

Exit_btn_cmd8_gjl_Click:
Exit Sub

Err_btn_cmd8_gjl_Click:
MsgBox Err.Description
Resume Exit_btn_cmd8_gjl_Click

End Sub
 
D

Douglas J. Steele

If it's a listbox on the same form, you should refer to it as Me.lst1_gjl.

What you have should work if the MultiSelect property is set to None. If
MultiSelect isn't None (i.e.: it's Simple or Extended), referring to the
listbox is going to return Null even if you've only selected a single value
from the list. In that case, you need to loop through all of the selected
items in the list, like what's illustrated in
http://www.mvps.org/access/forms/frm0007.htm at "The Access Web"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top