Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GoToRecord for subforms? 3

Status
Not open for further replies.

shar

Technical User
Apr 2, 2000
54
IR
I have a parentform with a subform and a subsubform. In the subform events, I want to run the "DoCmd.GoToRecord acDataForm, formname, acFirst" command for the subsubform. However, the formname is giving me trouble.

If I just use the subsubform name, I get an "object not loaded" error. If I use the complete name (Forms!parentform!subform!subsubform) I get a "wrong data type for argument" error.

Anyone knows the correct way to refer to nested subforms in this docmd?

Thanks.
Shar
 
To get to a subform from within its parent form, use the syntax:
Forms!<mainform>!<subformcontrol>.Form

Thus, to get to a sub-subform from within the main form, you'd use:
Forms!<mainform>!<subformcontrol>.Form!<sub-subformcontrol>.Form

To invoke the GoToRecord method, then:
Forms!<mainform>!<subformcontrol>.Form!<sub-subformcontrol>.Form.GoToRecord <argument> Rick Sprague
 
RickSpr,
Thanks for the response. The way you have written the statement &quot; Forms!<mainform>!<subformcontrol>.Form!<sub-subformcontrol>.Form.GoToRecord <argument>&quot; produces Run-time error 2465: Application-defined or object-defined error.

I have tried using this format in the docmd method: &quot;DoCmd.GoToRecord acDataForm, <frm>, acFirst&quot;. However, the complete form reference (parent, sub, subsub) gives Run-time error 2498, wrong data type. The docmd, according to the help text, requires a &quot;string expression&quot; for the object name. How do you express the <mainform, sub, sub-sub> in string format?
 
What was I thinking? Sorry, shar, there is no form GoToRecord method. I answered from memory, and my memory was wrong.

DoCmd.GoToRecord can only change positioning in the recordset of the main form. The reason is that subforms are not real forms; they don't have title bars, close boxes, etc.

Here's what you can do that's almost the same thing, though. Put the following procedure in your sub-subform:
Code:
    Public Sub MoveToRecord(RecNo As Integer)
        Dim rst As Recordset
        Set rst = Me.RecordsetClone
        rst.MoveFirst
        If RecNo > 1 Then rst.Move RecNo - 1
        Me.Bookmark = rst.Bookmark
        Set rst = Nothing
    End Sub
Then replace the DoCmd.GoToRecord in your main form with:
Me!<subformctl>.Form!<sub-subformctl>.Form.MoveToRecord <recno>

(This time I tested it before I gave you an answer, so no more bad advice. Sorry about that!) Rick Sprague
 
Thank you RickSpr, works perfect!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top