Access - auto populate text boxes

reicherb

Platinum Member
Nov 22, 2000
2,122
0
0
I've posted about this before but with limited success.

I've got a form with multiple text boxes and a combo box. All boxes reference the same table. When an item is selected in the combo box, I'd like the corresponding data to be automatically populated in the text boxes. How is that done?

Thanks.
 

bunker

Lifer
Apr 23, 2001
10,572
0
71
In the onChange event of the drop down, write some code to set the value of the text box = to the database field based on what was selected.
 

reicherb

Platinum Member
Nov 22, 2000
2,122
0
0
Would you be willing to give me an example? The table is called PC Models. The combo box field is called model. One of the text box fields is called CPU.

Thanks.
 

bunker

Lifer
Apr 23, 2001
10,572
0
71
Dim db As DataBase
Dim rs As DAO.Recordset

Set db = CurrentDb()

Set rs = db.OpenRecordset("SELECT * FROM 'PC Models' WHERE database field name for combo box='" & Forms!Form1!model & "' ")

If Not rs.EOF Then
Me.CPU.Value = rs("datbase field name for text field")
Else
MsgBox ("Error")
End If

The only thing I'm not sure of is the parenthesis around the table name. I never use two word names because of how finicky access is with spaces.

After the equals in the select statement the quotes go like this - single double double single double (hard to see in this forum)
 

reicherb

Platinum Member
Nov 22, 2000
2,122
0
0
Actually the field and the table are both called "PC Models" I just tried your code with and without the quotes but it didn't work. If your willing to look at it, the db can be seen here.

Thanks.