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

Adding a Value to a Combo Box

Status
Not open for further replies.

JerSand

Technical User
Oct 25, 2000
74
US
I'm attempting to build a fairly simple two-part set of cascading combo boxes. I have constructed two tables -- agencies and subagencies -- with the following SQL (creating a query called "qryAgencies"):

SELECT DISTINCT [Agencies].[Agency], [Agencies].[AgencyID], [SubAgencies].[SubAgency]
FROM Agencies INNER JOIN SubAgencies ON [Agencies].[AgencyID]=[SubAgencies].[AgencyID];

This query yields 133 combinations of agencies and subagencies.

Then, I constructed a form to write to a table I've named "DataRepository" and which holds an agency field, a subagency field, and some other descriptors of each observation. To enter a value in the agency field, I've constructed a combo box called "ComboAgencies" and used the following SQL as the row source:

SELECT DISTINCT [QryAgencies].[Agency] FROM QryAgencies;

This renders 12 agencies from which to choose. Based on the selection in that first combo box, a second combo box (called "ComboSubs") then restricts the possible choices to the selected agency's subagencies with the following SQL as the row source:

SELECT [QryAgencies].[SubAgency], [QryAgencies].[Agency] FROM QryAgencies WHERE ((([QryAgencies].[Agency])=[ComboAgencies]));

So far, this works. My problem is that I can't figure-out how to make a Requery macro work to add values to the combo boxes when the user enters an agency or subagency that was not originally defined in the query "qryAgencies" or in the tables on which that query is based. The basic problem, I guess, is that the new values are being written not to the original tables, but to the table constructed to receive input ("DataRepository").

I'd be grateful for suggestions.

Thanks.

JerSand
 
You could use the NotInList event of the combo box. Here you could use code to add their value to respective table and anything else you need to do.

Hope this helps....
 
Thank you, jitter. My VBA skills are weak, but your idea seems on the money, so I'll give it a try. I'm grateful for your response.

JerSand
 
Thank you, jitter. My VBA skills are weak, but your idea seems on the money, so I'll give it a try. I'm grateful for your response.

JerSand
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top