Move to Last Record on datasheet form

  • Thread starter Thread starter Jumbo Shrimps
  • Start date Start date
J

Jumbo Shrimps

I would like the cursor to move to the last record (plus
one more) of a datasheet sub-form. If there are ten
records in the query the data sheet sub-form is based on
for example, that match the same ID as the master form, I
would like the cursor on the sub-form to be on the
eleventh record (a new record).
 
Jumbo Shrimps said:
I would like the cursor to move to the last record (plus
one more) of a datasheet sub-form. If there are ten
records in the query the data sheet sub-form is based on
for example, that match the same ID as the master form, I
would like the cursor on the sub-form to be on the
eleventh record (a new record).

Here's one way. The code is designed to be run from the main form, and
it assumes the subform control (on the main form) is named "Subform1".
Obviously you have to replace that with the actual name of the subform
control -- note that this may or may not be the same as the name of the
form object begin displayed in that control.

Me!Subform1.SetFocus
RunCommand acCmdRecordsGoToNew
 
Got an error message run-time error '2046'
"The command or action 'RecordgotoNew' is not
available right now."


Here's one way. The code is designed to be run from the
main form, and
it assumes the subform control (on the main form) is
named "Subform1".
Obviously you have to replace that with the actual name of
the subform
control -- note that this may or may not be the same as
the name of the
form object begin displayed in that control.

Me!Subform1.SetFocus
RunCommand acCmdRecordsGoToNew
 
JumboShrimps said:
Got an error message run-time error '2046'
"The command or action 'RecordgotoNew' is not
available right now."

[Dirk Goldgar wrote:]
Here's one way. The code is designed to be run from the
main form, and
it assumes the subform control (on the main form) is
named "Subform1".
Obviously you have to replace that with the actual name of
the subform
control -- note that this may or may not be the same as
the name of the
form object begin displayed in that control.

Me!Subform1.SetFocus
RunCommand acCmdRecordsGoToNew

Hmm. I wonder why. Please explain more about the context in which you
are running the code. There are other ways to do it, but I need to know
why this doesn't work before advising you further.
 
Thanx for your reply.
The acCmdRecordsGoToNew works if I place it
on the load event of the subform, and open the
form by itself BUT
the subform only loads once (right?) on the main
form. Need a way to call acCmdRecordsGoToNew
every time a new record is selected from the main
form. (Placing RunCommand acCmdRecordsGoToNew
on the Current event of the main form doesn't
work either.



Me!Subform1.SetFocus
RunCommand acCmdRecordsGoToNew

Hmm. I wonder why. Please explain more about the context
in which you
are running the code. There are other ways to do it, but
I need to know
why this doesn't work before advising you further.


Dirk Goldgar, MS Access MVP
www.datagnostics.com
 
JShrimps Jr. said:
Thanx for your reply.
The acCmdRecordsGoToNew works if I place it
on the load event of the subform, and open the
form by itself BUT
the subform only loads once (right?) on the main
form. Need a way to call acCmdRecordsGoToNew
every time a new record is selected from the main
form. (Placing RunCommand acCmdRecordsGoToNew
on the Current event of the main form doesn't
work either.

It *does* work, but I find that it raises an error if the subform is
already on the new record -- if, for example, there are no existing
subform records. Try this for the main form's Current event:

---- start of code ----
Private Sub Form_Current()

With Me!Subform1
.SetFocus
If Not .Form.NewRecord Then
RunCommand acCmdRecordsGoToNew
End If
End With

End Sub
---- end of code ----

Replace "Subform1" with the name of the subform control on the main
form.
 
Back
Top