How do I Goto the Last Record in a Subform?

  • Thread starter Thread starter Steven V. Olson
  • Start date Start date
S

Steven V. Olson

OK! Here's the problem. I have Access Developer 2000. I
have requeried a form to get the most accurate data.
However, I was working on the last record of the subform.
When I requeried using VBA, the subform resets to the
first record in the form. I have tried using
DoCmd.GoToRecord, and DoCmd.GoToControl, however neither
command recognizes that the subform is even open.
DoCmd.GoToControl does not recognize the subform as a
control. How can I use VBA to Navigate to the last record
in the subform.

Steve Olson
 
Hi Steven,

The docmd commands don't work because the subform is not open as a member of
the forms collection. Instead it is you have to reference it through the
subform control on the main form. Here's one way to get to the last record
on the subform:

Replace 'sfrmMySub' with the name of the subform control on the main form.
Note that this is not necessarily the same name as the name of the form
object itself (as seen in the database window). To be sure, open the main
form then click once on the subform then check the name property under the
Other tab on the property sheet. This is the name to use below.

with me.sfrmMySub.form.recordsetclone
' make sure there is at least one record
if not .eof and .bof then
.movelast
me.sfrmMySub.form.bookmark=bookmark
endif
end with
 
Thanks Sandra,

I'll try that right away.

Steve Olson
-----Original Message-----
- slight correction - this line had a missing period in front of the second
'bookmark' - it should be as follows:

me.sfrmMySub.form.bookmark=.bookmark


--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Sandra said:
Hi Steven,

The docmd commands don't work because the subform is not open as a member
of the forms collection. Instead it is you have to reference it through
the subform control on the main form. Here's one way to get to the last
record on the subform:

Replace 'sfrmMySub' with the name of the subform control on the main form.
Note that this is not necessarily the same name as the name of the form
object itself (as seen in the database window). To be sure, open the main
form then click once on the subform then check the name property under the
Other tab on the property sheet. This is the name to use below.

with me.sfrmMySub.form.recordsetclone
' make sure there is at least one record
if not .eof and .bof then
.movelast
me.sfrmMySub.form.bookmark=bookmark
endif
end with

.
 
Back
Top