blacksaibot
Registered User.
- Local time
- Today, 00:46
- Joined
- Jan 20, 2010
- Messages
- 31
I know how to do this in VB.NET but VBA is killing me!!!
I have a form with a combo box. I would like to create an "on change" event where it updates the text boxes on that same form depending on what's been selected in the combo box.
I don't know how to change the combo box's selected index so it defaults to the first item so there's no blanks/errors in my form.
So when the combobox contents is changed, I'd like a routine that updates all the text boxes kind of like this:
sub update()
TextBox = "SELECT * FROM Table_Name WHERE ID =" & Combobox.text
end sub
In other words, selecting something from the combox runs a query to grab and fill out textboxes with data from the DB.
I've tried something like this...
How do I work with recordsets so I can assign the values from my query results to the other text fields??
Thanks in advance for your help!
I have a form with a combo box. I would like to create an "on change" event where it updates the text boxes on that same form depending on what's been selected in the combo box.
I don't know how to change the combo box's selected index so it defaults to the first item so there's no blanks/errors in my form.
So when the combobox contents is changed, I'd like a routine that updates all the text boxes kind of like this:
sub update()
TextBox = "SELECT * FROM Table_Name WHERE ID =" & Combobox.text
end sub
In other words, selecting something from the combox runs a query to grab and fill out textboxes with data from the DB.
I've tried something like this...
Code:
Option Compare Database
Private Sub cbx_UserID_BeforeUpdate(Cancel As Integer)
Call updateTextFields
End Sub
Private Sub updateTextFields()
Dim DescrSQL As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
cbx_UserID.SetFocus
DescrSQL = "SELECT Surveys.[Duty_Pos] FROM Surveys WHERE Surveys.[User_ID]='" & cbx_UserID.Text & "';"
Set db = CurrentDb()
Set rs = db.OpenRecordset(DescrSQL)
rs.Close
db.Close
End Sub
How do I work with recordsets so I can assign the values from my query results to the other text fields??
Thanks in advance for your help!