Subform Navigation

D

Doc

Hey all,

I have a little piece of code I use for form navigation, and would like it
to be able to work for sub forms, as well as the main form.

I call the function with the OnClick event property, example such as
=GoToRec("Form1","Next").

When the code attempts to run from a subform, it states the the form can not
be found. Can anyone help with modifying the current code to include the
ability to navigate inside subforms?

Thanks!

Code:

Function GoToRec(frm As String, opt As String)
On Error GoTo ErrHand

If opt = "First" Then DoCmd.GoToRecord acDataForm, frm, acFirst
If opt = "Last" Then DoCmd.GoToRecord acDataForm, frm, acLast
If opt = "Next" Then DoCmd.GoToRecord acDataForm, frm, acNext
If opt = "New" Then DoCmd.GoToRecord acDataForm, frm, acNewRec
If opt = "Prev" Then DoCmd.GoToRecord acDataForm, frm, acPrevious

Exit Function

ErrHand:
Select Case Err.Number
Case 2105
Exit Function
Case Else
ErrorLog "MDSSFunc", "GoToRec", "eMf-215",
Screen.ActiveForm.Name, Err.Number, Err.Description
End Select
End Function
 
M

Marshall Barton

Doc said:
I have a little piece of code I use for form navigation, and would like it
to be able to work for sub forms, as well as the main form.

I call the function with the OnClick event property, example such as
=GoToRec("Form1","Next").

When the code attempts to run from a subform, it states the the form can not
be found. Can anyone help with modifying the current code to include the
ability to navigate inside subforms?

Thanks!

Code:

Function GoToRec(frm As String, opt As String)
On Error GoTo ErrHand

If opt = "First" Then DoCmd.GoToRecord acDataForm, frm, acFirst
If opt = "Last" Then DoCmd.GoToRecord acDataForm, frm, acLast
If opt = "Next" Then DoCmd.GoToRecord acDataForm, frm, acNext
If opt = "New" Then DoCmd.GoToRecord acDataForm, frm, acNewRec
If opt = "Prev" Then DoCmd.GoToRecord acDataForm, frm, acPrevious


Use the form's recordset with the MoveFirst, Move Next, ...
methods instead of GoToRecord
 
D

Doc

Hmm, thanks bhicks! Took out the objecttype and name and sure enough, works
like a charm.

Thank you!
 

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