Select record from list box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I made a list box that filter queries the total records in a subform. How do I program it so I can select a record in the list box and then have the subform go directly to that record. As it stands now, I can only visulaize the list of records, not activate them.
 
-----Original Message-----
I made a list box that filter queries the total records
in a subform. How do I program it so I can select a
record in the list box and then have the subform go
directly to that record. As it stands now, I can only
visulaize the list of records, not activate them.

Supposing that you have a form TheNameOfYourForm with a
listbox List0 on it and a command button next to it named
cmdShowRecord then:

Private Sub cmdShowRecord_Click()
'Find the selected record then close the dialog box

Dim rst as DAO.Recordset

'Store the recordset for your form
Set rst = Forms!TheNameOfYourForm.RecordSetClone

'Locate the selected record
rst.FindFirst "YourEntryID = " & List0

'Set the form's bookmark property to move to the record
Forms!TheNameOfYourForm.Bookmark = rst.Bookmark

'Close the dialog box
DoCmd.Close acForm, "TheNameOfYourForm"

End Sub>

I hope it works for you, George
 
Thanks so much, but I'm using a subform and I can seemt o get teh syntax right. The form name is DEMO and the subform name is CLINDATA. Both are linked using CLINID
Please help, thank you so much.
 
Melissa,

I assume that you want to display in the subform the record(s) which have a
CLINID matching the record selected in the listbox.

You must have CLINID as a column in your listbox query. I'll assume here is
is the bound column.

You can then add to the ListBox_AfterUpdate event code which changes the
RecordSource of CLINDATA

Private Sub ListBox_AfterUpdate()
CLINDATA.RecordSource = "SELECT * FROM QueryYouAreUsingNow WHERE
CLINID=" & ListBox
End Sub

Rod Scoullar
 
Back
Top