J
Joe
Hi, I need your help adapting this example to using a record that is
selected by an Unbound Combo Box on a form instead of a static value
in the VBA code. Everything works in my example and all I really need
to do is to change the static line below of: rsContacts.Find
"[intContactId] = 2" with the selected record in my Combo Box. Any
help is appreciated.
Thanks!
Sub TestFind()
Dim rsContacts As ADODB.Recordset
'create a new instance of a recordset
Set rsContacts = New ADODB.Recordset
'set various properties of the recordset
With rsContacts
.CursorType = adOpenStatic
'open the recordset based on tblContacts table using the existing
connection
.Open "tblContacts", CurrentProject.Connection
End With
'find a contact with the intContactId value of 2
rsContacts.Find "[intContactId] = 2"
'output a message to the Immediate Window regarding find results
If rsContacts.EOF Then
Debug.Print "Specified record not found"
Else
'record was found - display some info
Debug.Print "Contact Id: " & rsContacts!intContactId & _
" Last Name: " & rsContacts!txtLastName & _
" First Name: " & rsContacts!txtFirstName
End If
'close the recordset
rsContacts.Close
'set the recordset and connection to nothing
Set rsContacts = Nothing
End Sub
selected by an Unbound Combo Box on a form instead of a static value
in the VBA code. Everything works in my example and all I really need
to do is to change the static line below of: rsContacts.Find
"[intContactId] = 2" with the selected record in my Combo Box. Any
help is appreciated.
Thanks!
Sub TestFind()
Dim rsContacts As ADODB.Recordset
'create a new instance of a recordset
Set rsContacts = New ADODB.Recordset
'set various properties of the recordset
With rsContacts
.CursorType = adOpenStatic
'open the recordset based on tblContacts table using the existing
connection
.Open "tblContacts", CurrentProject.Connection
End With
'find a contact with the intContactId value of 2
rsContacts.Find "[intContactId] = 2"
'output a message to the Immediate Window regarding find results
If rsContacts.EOF Then
Debug.Print "Specified record not found"
Else
'record was found - display some info
Debug.Print "Contact Id: " & rsContacts!intContactId & _
" Last Name: " & rsContacts!txtLastName & _
" First Name: " & rsContacts!txtFirstName
End If
'close the recordset
rsContacts.Close
'set the recordset and connection to nothing
Set rsContacts = Nothing
End Sub