docmd.gotorecord on a sub form

G

Geoffrey

Does anyone know how to position on a record on a sub form.

Sub form is called EasyBookerSelectFlight

reccount = [EasyBookerSelectFlight].form.currentrecord
me.[EasyBookerSelectFlight].requery
docmd.gotorecord, acdataform, "EasyBookerSelectFlight", reccount

gets an error message
 
D

Dirk Goldgar

Geoffrey said:
Does anyone know how to position on a record on a sub form.

Sub form is called EasyBookerSelectFlight

reccount = [EasyBookerSelectFlight].form.currentrecord
me.[EasyBookerSelectFlight].requery
docmd.gotorecord, acdataform, "EasyBookerSelectFlight", reccount

gets an error message

Syntactically, you can do it like this:

With Me!EasyBookerSelectFlight
reccount = .Form.CurrentRecord
.Requery
.SetFocus
End With
DoCmd.GoToRecord acActiveDataObject, , acGoTo, currentrecord

Thinking about this logically, though, this method *must* be unreliable,
since you cannot know that the same record will be in the same position
in the recordset -- or even present at all -- after you requery the
subform. A better approach is to capture the value of the current
record's primary key field, then go back to that record by finding the
primary key. Like this:


Dim RecID As Variant

With Me!EasyBookerSelectFlight.Form
RecID = !IDField.Value
.Requery
.Recordset.FindFirst "IDField = " & RecID
End With

Note that, if IDField is a text field, you have to change the FindFirst
criteria so that the value of RecID is enclosed in quotes; e.g.,

.Recordset.FindFirst _
"IDField = " & Chr(34) & RecID & Chr(34)
 
Joined
Feb 1, 2011
Messages
1
Reaction score
0
I wanted to thank Dirk for pointing me in the right direction. However, Dirk's solution didn't work for me because I'm trying to go to a specific record on a subform.

Here's the solution that worked for me where SPU_ID is the primary key to record set.

With Forms!MyMainForm!MySubForm.Form
.Recordset.FindFirst "SPU_ID = " & lngSPU_ID_Cur
End With

Thank you very much, Curt
 

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