I have the combo box populated with the last names of the customers in the database. How do I get the text boxes on the form to fill with the customer data from the database when the lastname in selected in the combobox.
There are about a zillion different ways to do this. You could use a data control and bind the text boxes to the database field names, but I intensely dislike bound controls, so I won't suggest that. If this does interest you however, there are many examples of how to do this in nearly everybook on beginning VB programming.
A better way would be to build a recordset based on an SQL call in which you SELECT all of the fields in your table that you want for Customer=Trim(cboCustomer.Text)
If you build your recordset on this SQL statement: SELECT firstname, address, city, state, zip FROM YourDatabaseName WHERE Customer=Trim(cboCustomer.Text)
Then, you can write a series of If/Then statements such as:
If IsNull(rs.Fields("firstname") Then
txtfirstname.Text = ""
Else
txtfirstname.Text = rs.Fields("firstname"
End If
Where rs=the name of your recordset, and firstname is the name of the First Name field in your db table.
There is a much nicer, tighter way of populating your text boxes, but this will work. If you are interested in something a bit more sophisticated, let me know.
Hi Hackster...
I know it was a while back when you posted this..but to take it a step further...is it possible to fill another combobox depending on what is selected in the first combobox..
my problem is this....
i have a list of counties in a combobox....
i want to be able to be able to select a county and then fill the second combobox with the towns in this county 'on the fly' if this is possible....
hope i am making myself clear???
thanks......
ronan
strSQL = "Select TownName from tblAddresses Where CountyName Like %" & Trim(cboCounties.text) & "%"
Then fill your second combo from the Recordset:
Do While Not rst.EOF
cboTowns.Additem rst!TownName
Loop Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first
'People who live in windowed environments shouldn't cast pointers.'
ok john...
but does this happen on the change event of the first combobox??
my problem is that i want the user to be able to change the selection in the first combo box and when he does, the second combo box will change its contents....
so do i program your code under the change event??
Change event, Click event, LostFocus event - Fire it from whatever event your pogram logic needs! Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first
'People who live in windowed environments shouldn't cast pointers.'
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.