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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate form based on listbox running from SQL

Status
Not open for further replies.

nunan

Technical User
Feb 11, 2004
41
0
0
GB
Hi

Could anyone offer some help please?

I have a form FrmReservations. On this form is a listbox AvailListBox running an sql query which finds data from 2 tables TblVehicles and TblReservations based on a date range which is in a subform FrmReservationDates.

The sql for the listbox is:
SELECT Reg, Colour, Model FROM TblVehicles WHERE Reg Not In (SELECT Reg FROM TblReservations WHERE ResStartDate Between [FrmReservationDates].Form![StartDate] And [FrmReservationDates].Form![EndDate] OR ResEndDate Between [FrmReservationDates].Form![StartDate] And [FrmReservationDates].Form![EndDate]);

This all works perfectly thanks to PHV!

On the form I have all the fields from TblVehicles and I want these to populate once I select an item from the listbox AvailListBox. However, I can't work out how to get this data to populate.

Any help is appreciated.

Thanks
 
Is your form bound to tblVehicles? If so, you can use the After Update event of the listbox to find your record:

[tt]Me.Recordset.FindFirst "Reg='" & Me.ListBox & "'"[/tt]

If the form is not bound, you can set the RecordSource programmatically:

[tt]Me.RecordSource = "Select * From tblVehicles Where Reg='" & Me.ListBox & "'"[/tt]

Both examples assume that Reg is in the bound coulumn, if not, you will need to reference the Column property of the listbox.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top