Pulling up a record using a combo box

D

Dave

I am trying to have it then when i select a record from
the combobox, it will go to that record, but for
somereason it is not working, here is the code:


Option Compare Database

Private Sub Combo39_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Phone Number] = '" & Me![Combo39] & "'"
Me.Bookmark = rs.Bookmark
End Sub
 
A

Albert D. Kallal

You could try building the combo box with the wizard..and it will make the
code for you.

However, your problem is:
Set rs = Me.Recordset.Clone

it should be:
Set rs = Me.RecordSetClone
 
V

Van T. Dinh

* Use the ComboBox Wizard to create the code for you.

* In the code, you should really check for NoMatch (check Access VB Help)
and only assign BookMark if NoMatch is False.

* Note that you use the value of the ComboBox in the FindFirst method and
the value may not be the same as what you see on screen (depending on the
bound Column of the ComboBox). You may need to check and make sure the
value of the ComboBox is the [Phone Number] value.
 
P

Pieter Wijnen

... and if not use the .column property ..
Option Explicit ' Always use to avoid typos

Private Sub Combo39_AfterUpdate()Dim rs As DAO.Recordset ' Early binding is better than late in this
case .... '''Objectrs.FindFirst "[Phone Number] = '" & Me![Combo39].Column(1) & "'" '
assume phone is seccond(!) columnrs.close : set rs = nothing ' clean up objects when you're done with
them ...
Pieter

Van T. Dinh said:
* Use the ComboBox Wizard to create the code for you.

* In the code, you should really check for NoMatch (check Access VB Help)
and only assign BookMark if NoMatch is False.

* Note that you use the value of the ComboBox in the FindFirst method and
the value may not be the same as what you see on screen (depending on the
bound Column of the ComboBox). You may need to check and make sure the
value of the ComboBox is the [Phone Number] value.

--
HTH
Van T. Dinh
MVP (Access)



Dave said:
I am trying to have it then when i select a record from
the combobox, it will go to that record, but for
somereason it is not working, here is the code:


Option Compare Database

Private Sub Combo39_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Phone Number] = '" & Me![Combo39] & "'"
Me.Bookmark = rs.Bookmark
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top