ComboBox_Change Event to Populate another Combox

T

Tobi

I have a userform that has a combobox for car makes, and I want to make
it so that when a make is selected, the box below it will be populated
with the models of that make.

I already have the makes populating the make comboboxes using ADO on
the UserForm_Initialize event.
I already have a table with all of the make/model info, there is a
column of models with a column that contains their makes, and to pull
the makes, i just SELECT DISTINCT Makes.

I tried making the ComboBox_change event connect and query the database
with the ComboBox.Text, but that causes all sorts of annnoying
ridiculously-hard-to-debug errors, and I am thinking that there must be
a smoother way to do this. Is there an event that occurs after the text
is changed and then idles? or is there a way I can make a combobox
intrinsically tied to an incomplete query, where the above box plugs
the missing link into the incomplete query and then connects and
retrieves the data?
 
B

Bob Phillips

How about the Enter event of the second combobox?

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
T

Tobi

I tried making a Model1_Enter event, and i get the error message:

"Compile error:
Expected user-defined type, not project"


I am not sure what to do, what I have is a function that connects to
the SQL Server via ADO, and the function takes in a SQL String as a
query, and then attempts to execute the query, and on error returns
false, so it trys and trys until the user gives a string that queries
cleanly, then returns the recordset.

Is there a comprehensive list of events in VB/VBA? I have the O'Reilly
VB/VBA in a nutshell book, and there is no list there, nor have I been
able to find one through search. I am stuck.
 
B

Bob Phillips

Tobi said:
I tried making a Model1_Enter event, and i get the error message:

"Compile error:
Expected user-defined type, not project"


I am not sure what to do, what I have is a function that connects to
the SQL Server via ADO, and the function takes in a SQL String as a
query, and then attempts to execute the query, and on error returns
false, so it trys and trys until the user gives a string that queries
cleanly, then returns the recordset.


I can't really help you with as little detail as that. Compilere error,
where in the code, I'm supposed to know?

Is there a comprehensive list of events in VB/VBA? I have the O'Reilly
VB/VBA in a nutshell book, and there is no list there, nor have I been
able to find one through search. I am stuck.


If you go into the VBIDE, and view code in the Userform. Select one of the
Combobox event procedures already there and then in the dropdown at the top
right of the code module, click on that and you see all events available for
a combobox.
 
T

Tobi

If you go into the VBIDE, and view code in the Userform. Select one of the
Combobox event procedures already there and then in the dropdown at the top
right of the code module, click on that and you see all events available for
a combobox.
Oh whoa, I totally missed that, thank you, I will more than likely be
able to figure this one out.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top