GoToRecord (Specific record) in subform using listbox

D

darien.watkins

I have a form with a listbox. I have a subform below bound to the
recordset of the listbox. I want to be able to click on the row and
push an edit button to have the selected record shown in the subform
below for editing. I'm doing something like this on the edit button:

Private Sub CommandButton_Click()
Dim ID As Integer

Me!SubForm.SetFocus
DoCmd.GoToRecord , , acGoTo, ID

End Sub

The problem is the ID I'm passing and the ID it's pulling aren't the
same thing. If the ID I'm trying to pull is too high, I will get a
Run-Time error 2105 - You can't go to the specified record. If it's
below that threshold, I just get the wrong record.

What am I missing here?

Darien
 
S

strive4peace

Hi Darien,

if you are looking for a record in the subform:

'~~~~~~~~~~~~~~~~~~~~~~~~~``
'find the first value that matches
Me.subform_controlname.form.RecordsetClone.FindFirst _
"ID = " & me.listbox_controlname

'if a matching record was found, then move to it
If Not Me.subform_controlname.form.RecordsetClone.NoMatch Then
Me.subform_controlname.formBookmark _
= Me.subform_controlname.form.RecordsetClone.Bookmark
End If
'~~~~~~~~~~~~~~~~~~~~~~~~~``

Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
D

darien.watkins

Thanks for the help. When I try the solution, I get a compile error
saying the the formBookmark Method or data member not found. I'm sure
I'm misunderstanding this since it's a departure from the way I was
trying to do it before. What did I do wrong?

Darien
 

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