Populate text box after combo box use

goosehunter

New Member
Joined
Dec 2, 2003
Messages
36
Hello everyone, this is my first post. I'm very impressed with the knowledge on this board. I've look around for my question but couldn't find the solution.

I have a "company table". If I select the name of a company with a combo box, how can I make it automatically populate the "address", "telephone number", "zip", etc. for that company in a text boxes right below the combo box? Thanks so much for any assistance!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hey goosehunter

There, there are two ways of doing this. One takes a large swipe at your computer resources by creating a copy of your dataset and generating a clone of the recordset. This is all good and well when you have a small table, but when you have a large amount of data to trawl through, that's when your resources take the hit.

The other way, and it's easier, is to just allow the form to read one row from the database table at a time. By telling the form just which row to view, you get away with as little as you can.

However, there is a catch (Surprise!!) By doing it this way, you must choose a new record implicitly to see new information i.e. You must chose a new company name from your combobox. This is because the record source for your form will just have one record instead of the entire recordset. Just bare that in mind.

So, with that in mind, let's begin.

You need to do two things.

Firstly, you need to create the dropdown list that will have the names of the companies in your database. I assume you already have that.

Next, you want to populate the textboxes below your combo box with the company data for the name in the combo box.

In design mode, right click your combobox, choose Build Event, and choose Code Builder. The Code Window will open. Add the following code:

Private Sub Combo__NumHere_Change()
Dim strCompanyName, strSQL As String

strCompanyName = Me.Combo__NumHere.Value

strSQL = "SELECT * FROM _TABLENAME_ WHERE _TABLENAME_.CompanyName = '" & strCompanyName & "'"

Me.RecordSource = strSQL
Me.Combo__NumHere.Value=""

End Sub


Where it says __NumHere you must add the number of your ComboBox, and where it says __TABLENAME, you add the name of your table where the data sits. Where it says __TABLENAME.CompanyName you add the Field name of you table where the company names are stored.

Try that goosehunter

anvil19
:eek:
 
Upvote 0

Forum statistics

Threads
1,221,586
Messages
6,160,646
Members
451,661
Latest member
hamdan17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top