-
populate textbox using combobox search in vba form
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.
[VBA]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[/VBA]
any solution?
-
Use
rstemp.field2
or
rstemp!field2
or
rstemp.[field2]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules