Select item in list box, display form

L

Lin

Help please, and thank you.

I have a listbox on a form based on a query. I want to double click on an
item and display results on another form. I have tried a few things and it
doesn't work.

Everything is based on an autonumber key field. How can this be done?
 
A

Alex White MCDBA MCSE

Hi Lin,

if your listbox is called lstContacts

then lstContacts.column(0) gives you the value of the first column of the
selected item.

for completeness I use

on the double click event

if not isnull(lstContacts.column(0)) then
form_myNewForm.Recordsource = "Select * from MyTable where myID=" &
lstContacts.Column(0)
form_myNewForm.Refresh
end if

Hope it helps.
 
L

Lin

Hi Alex thanks for reply...still not working

This is what I have

If Not IsNull(lstResults.Column(0)) Then
frmFSMain.RecordSource = "Select * from tblFSMain where FSFileID=" &
lstResults.Column(0)
frmFSMain.Refresh
End If

What did I do wrong

Sorry to be such a bother ....and thanks again
 
A

Alex White MCDBA MCSE

Hi Lin,

what columns are in use in the listbox, for the below example to work, the
FSFileID column on the listbox has to be the first column, if you don't want
to show it make the 'column widths' property something like '0cm;3cm'

Hope it helps
 
Top