View Full Version : Search with list boxes


sarthur
10-11-2001, 09:33 PM
I have three tables used in a form:
tblCompany : CompanyID (PK), CompanyName, etc
tblProject : ProjectID (PK), ProjectName, CompanyID (FK), etc
tblQuote : QuoteNumber (PK), ProjectID (FK), etc
NOTE: PK = Primary Key; FK = Foreign Key

What I'm trying to achieve is a form for entering new Quotes. This form requires the user to select the CompanyName in one list box and the ProjectName in another, from which a QuoteNumber is generated. What I'd like to happen is that when the CompanyName is changed in one list box, then the list box for the ProjectName will only allow a selection of projects from the Project Table with the same CompanyID. I have somewhat achieved this using DLookup(), however the problem is that I've linked the data in the list boxes to the tables, so that if I change the CompanyName, then the CompanyID is changed in the Project Table. This means the Project is associated with the wrong Company!
What is the best way to achieve this?

jwindon
10-12-2001, 03:03 PM
Go into your form view and create two UNBOUND comboboxes. The wizard will ask you about the information you want displayed in your combo.

For the first:

tblCompanyName
CompanyID, CompanyName
Hide Key Column yes

For the second:

tblProject
ProjectID, ProjectName, CompanyID
Hide key column

Now, you need to adjust the second combo a little. Right click on that combobox in design view and goto properties, data, somewhere a few lines down, you will see [SELECT.....

Click on the build button next to that row and a window that looks like a query will appear showing the three fields you chose in the wizard. On the Criteria line under CompanyID write [WriteTheNameOfTheFirstComboBoxNameHere]

close, save the changes YES

Now after you select the first value, the second combo should show the values the match the CompanyID in the first combo.

sarthur
10-14-2001, 07:01 PM
Thanks mate!
You are my asprin http://www.access-programmers.co.uk/ubb/smile.gif