Items selected from List Box

G

Guest

I would like to display records in a list box, allow the user to select one
or more, then click a button on the form and be brought to another form that
allows him to edit just those selected records.
I have created and populated the list box, and designed the form to edit the
records, but don’t know how to supply the 2nd form with the criteria that is
coming from the list box (which records to display)
This probably quite easy, but can’t find an example of how this is done in
any of the sample templates available on the Microsoft site. Any help is
greatly appreciated.
 
D

Dale Fye

jklm,

Assuming that your the bound column of your listbox is a long integer
datatype, you could do the following:

Public Sub cmd_OpenSelected_Click

Dim varCriteria as variant, strCriteria as string
Dim varItem as variant

'If no item was selected, display an error message
if me.lst_yourlistboxname.ItemsSelected.count = 0 then
msgbox "Select one or more records to edit!
exit sub
endif

'loop through each selected item, appending the first (assumes
BoundColumn = 1) column
For each varItem in me.lst_yourlistboxname.ItemsSelected
varCriteria = (varCriteria + ", ") &
me.lst_yourlistboxname.Column(0, varItem)
Next

'[fieldname] is the name of the ID field in your form that matches the
listbox
'bound column
strCriteria = cstr("[fieldname] IN (" + varCriteria + ")"

docmd.OpenForm FormName:="frm_Listbox", WhereCondition:=strCriteria

End sub
 

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

Top