GoToRecord

T

Tara

I have a parent form with a child form accessed through a toggle button. I
would like the child form to display the last record when opened. I have the
following code in the On Open event of the child form:

Private Sub Form_Open(Cancel As Integer)
DoCmd.GoToRecord , , acLast
End Sub

I also tried it in the On Load event, but it isn't working in either place.

Any advice is appreciated!
 
G

GH

I have a parent form with a child form accessed through a toggle button. I
would like the child form to display the last record when opened. I have the
following code in the On Open event of the child form:

Private Sub Form_Open(Cancel As Integer)
DoCmd.GoToRecord , , acLast
End Sub

I also tried it in the On Load event, but it isn't working in either place.

Any advice is appreciated!

This works for me in the OnLoad event with no problems. Are you
getting any errors? Have you tried stepping through the execution to
see what is happening? Are you possibly performing some action after
the DoCmd that changes the record, such as a filter or link to the
parent form record?

- GH

- GH
 
A

Allen Browne

This form is bound to a table or query?
If it's a query, it is updatable?
And the form's AllowAdditions property is Yes?
Are you getting any error messages?

If so, it should work. Like GH, I would prefer the form's Load event.
Try this:

Private Sub Form_Load()
If Not Me.NewRecord Then
RunCommand acCmdRecordsGotoNew
End If
End Sub
 
T

Tara

I haven't stepped through the execution yet. I'm a novice at coding and
hadn't thought of that. As for the other question, there is other code in
the OnLoad event that I supose could be creating an issue for me, but I'm not
sure. Here it is:

Sub Form_Load()
On Error GoTo Form_Load_Err

If ParentFormIsOpen() Then Forms![frmContactInfo]!ToggleLink = True



Form_Load_Exit:
Exit Sub

Form_Load_Err:
MsgBox Error$
Resume Form_Load_Exit

End Sub

I have since deleted the DoCmd.

Thanks for the feedback!
 
T

Tara

Thanks for the response Allen. The form is bound to the table
"tblScreenData" and I'm getting no error messages.

I tried the code you suggested but it doesn't seem to be doing the trick
either. Again, no error message when the code is inserted. The form opens,
but instead of showing the last record, it still shows the first one.

Any other suggestions?

Thanks!
 

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