PDA

View Full Version : populate textbox using combobox search in vba form



rocky_enc
07-31-2010, 10:32 AM
I am trying to populate text boxes of vba form using the value in combobox which is already populated with the data from access database.

but when I run the following code I get

Runtime Error 91: Object variable or with block variable not set

and it points to the line highlighted in the following code.

Private Sub ComboBox1_change()

Dim dbTemp As DAO.Database
Dim rsTemp As DAO.Recordset

Set dbTemp = CurrentDb()

Set rsTemp = dbTemp.OpenRecordset("SELECT field2, field3 FROM table1 where [field1] = '" & Str(Me.ComboBox1.Value) & "'")

If rsTemp.EOF = False Then
Me.TextBox2.Value = rsTemp("field2")
Me.TextBox3.Value = rsTemp("field3")
Else
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
End If

rsTemp.Close
rsTemp = nothing

End Sub

any solution?

OBP
08-02-2010, 04:22 AM
Use
rstemp.field2
or
rstemp!field2
or
rstemp.[field2]