Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ListBox Lookup with Subform 1

Status
Not open for further replies.

Sherman123

Technical User
Mar 31, 2004
5
GB
I have a main form with a ListBox being used to find records that match the selected value. This works fine when I click in the List Box, but when I use code to select an item in the Listbox it does not do anything.
I am using:
Code:
Form_FlightsTest.Lst1.SetFocus
    Form_FlightsTest.Lst1.Selected(0) = True
to select the 1st item in the List Box.
Using the above code selects the correct item in the ListBox but does not show the correct data on the form.
Any help appreciated. Thanks
 
A number of events are not triggered when the value of a control is changed programmatically.
 
Hi Remou,

I am creating a report and when I close the report I want to select the 1st item in the list box and find that record on the form.

Thanks
 
You can add some code to the Close event of the report, for example:

[tt]Forms!frmForm.Recordset.FindFirst "ID=" & Forms!frmForm.lstList.Columns(0,0)[/tt]

That is, find the record with an ID that corresponds to the number in the first row and the first column of the listbox.
 
Thanks again Remou,

I have this code in the report close event:
Code:
Form_FlightsTest.Recordset.FindFirst "Fltno=" & Form_FlightsTest.Lst1.Columns(0, 0)
When I close the report it finds an error on method or data member not found, Columns(0,0)

 
Oops. Column, not Columns.

It is best to use the forms collection.
 
Getting closer,

I now get error 3077, missing operator in expression.

Code:
Form_FlightsTest.Recordset.FindFirst "Fltno=" & Form_FlightsTest.lst1.Column(0, 0)
 
Is FltNo a text field? If so:

Code:
Forms!FlightsTest.Recordset.FindFirst "Fltno='" & Forms!FlightsTest.lst1.Column(0, 0) & "'"
 
Thanks Remou,

With a little modification it now works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top