Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: Move to last record after form opened

Geek News

Move to last record after form opened
BrunoKP 12/12/2008 8:10:01 AM
I want a form coded to move to the last record immediately after the form has
been opened.
I don't want the recordset to be sorted, and I can't use Open event as the
first record has not yet been displayed.
RE: Move to last record after form opened
Maurice 12/12/2008 12:56:01 PM
if it's an editable form you could use something like:

docmd.openform "formname",,,, acformAdd

this will take you to a new record in the form. In a continuous form that
will show the last record and a new record where you can start typing...
--
Maurice Ausum


"BrunoKP" wrote:

[Quoted Text]
> I want a form coded to move to the last record immediately after the form has
> been opened.
> I don't want the recordset to be sorted, and I can't use Open event as the
> first record has not yet been displayed.
RE: Move to last record after form opened
BrunoKP 12/12/2008 2:03:01 PM
Hello Maurice
No I don't want to add a new record, I just want to move to the last
existing record.
I have tried this, but end up in the first record:

Private Sub Form_Load()
Dim rst As dao.Recordset
Dim dbsCurrent As Database

Set dbsCurrent = CurrentDb()
Set rst = Me.RecordsetClone
rst.MoveLast
rst.Close
dbsCurrent.Close
End Sub

I suppose that the recordset has not yet been displayed when Form_Load() is
activated. The question is, which event is the right one to use?

Thank you
Bruno

"Maurice" skrev:

[Quoted Text]
> if it's an editable form you could use something like:
>
> docmd.openform "formname",,,, acformAdd
>
> this will take you to a new record in the form. In a continuous form that
> will show the last record and a new record where you can start typing...
> --
> Maurice Ausum
>
>
> "BrunoKP" wrote:
>
> > I want a form coded to move to the last record immediately after the form has
> > been opened.
> > I don't want the recordset to be sorted, and I can't use Open event as the
> > first record has not yet been displayed.
RE: Move to last record after form opened
Maurice 12/12/2008 2:25:01 PM
In that case try this in the Open event of the form:

DoCmd.RunCommand acCmdRecordsGoToLast

that should do the trick...
--
Maurice Ausum


"BrunoKP" wrote:

[Quoted Text]
> Hello Maurice
> No I don't want to add a new record, I just want to move to the last
> existing record.
> I have tried this, but end up in the first record:
>
> Private Sub Form_Load()
> Dim rst As dao.Recordset
> Dim dbsCurrent As Database
>
> Set dbsCurrent = CurrentDb()
> Set rst = Me.RecordsetClone
> rst.MoveLast
> rst.Close
> dbsCurrent.Close
> End Sub
>
> I suppose that the recordset has not yet been displayed when Form_Load() is
> activated. The question is, which event is the right one to use?
>
> Thank you
> Bruno
>
> "Maurice" skrev:
>
> > if it's an editable form you could use something like:
> >
> > docmd.openform "formname",,,, acformAdd
> >
> > this will take you to a new record in the form. In a continuous form that
> > will show the last record and a new record where you can start typing...
> > --
> > Maurice Ausum
> >
> >
> > "BrunoKP" wrote:
> >
> > > I want a form coded to move to the last record immediately after the form has
> > > been opened.
> > > I don't want the recordset to be sorted, and I can't use Open event as the
> > > first record has not yet been displayed.
Re: Move to last record after form opened
Marshall Barton <marshbarton[ at ]wowway.com> 12/12/2008 5:09:13 PM
BrunoKP wrote:
[Quoted Text]
>I have tried this, but end up in the first record:
>
>Private Sub Form_Load()
> Dim rst As dao.Recordset
> Dim dbsCurrent As Database
>
> Set dbsCurrent = CurrentDb()
> Set rst = Me.RecordsetClone
> rst.MoveLast
> rst.Close
> dbsCurrent.Close
>End Sub
>
>I suppose that the recordset has not yet been displayed when Form_Load() is
>activated. The question is, which event is the right one to use?


NOTE: You should never use Close on something you did not
Open!

When you use RecordsetClone, you have to sync the form's
current record to the RecordsetClone's current record:

With Me.RecordsetClone
.MoveLast
Me.Bookmark = .Bookmark
End With

OTOH, In A2000 and later, for the simple operation you want
to do here, there is no need to use RecordsetClone (and
possibly have to deal with an emptry recordset). It is
simpler to use:

Me.Recordset.MoveLast

--
Marsh
MVP [MS Access]
Re: Move to last record after form opened
BrunoKP 12/13/2008 12:05:01 PM
I'm happy to use the simple and elegant solution: Me.Recordset.Movelast in
Form_Open.

Thank you Maurice and Marshall

"Marshall Barton" skrev:

[Quoted Text]
> BrunoKP wrote:
> >I have tried this, but end up in the first record:
> >
> >Private Sub Form_Load()
> > Dim rst As dao.Recordset
> > Dim dbsCurrent As Database
> >
> > Set dbsCurrent = CurrentDb()
> > Set rst = Me.RecordsetClone
> > rst.MoveLast
> > rst.Close
> > dbsCurrent.Close
> >End Sub
> >
> >I suppose that the recordset has not yet been displayed when Form_Load() is
> >activated. The question is, which event is the right one to use?
>
>
> NOTE: You should never use Close on something you did not
> Open!
>
> When you use RecordsetClone, you have to sync the form's
> current record to the RecordsetClone's current record:
>
> With Me.RecordsetClone
> .MoveLast
> Me.Bookmark = .Bookmark
> End With
>
> OTOH, In A2000 and later, for the simple operation you want
> to do here, there is no need to use RecordsetClone (and
> possibly have to deal with an emptry recordset). It is
> simpler to use:
>
> Me.Recordset.MoveLast
>
> --
> Marsh
> MVP [MS Access]
>
Re: Move to last record after form opened
Marshall Barton <marshbarton[ at ]wowway.com> 12/13/2008 2:57:54 PM
BrunoKP wrote:

[Quoted Text]
>I'm happy to use the simple and elegant solution: Me.Recordset.Movelast in
>Form_Open.


The Open event is supposed to be too early to do that. The
Load event is the recommended place for this kind of thing.
I can't explain why, but if it works ...

--
Marsh
MVP [MS Access]

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net