move to last record + 1 on form load.

  • Thread starter Thread starter mcnews2k
  • Start date Start date
M

mcnews2k

what is the most reliable way to move to the last record + 1 when a form
loads. i tried using docmnd.gotorecord, acForm, "myform", aclast (whatever
the syntax is) and it worked sometinme but not always.
tried using me.recordsetclone as well with similar results.
i'm now using a global veriable that gets set when MDB opens or when a
record is added the the main table.
what i have are several 1 to 1 tables and forms. all tables get a record
added to them whenever the main table gets appended to. this always works
when i use the app, but of course users do everything wrong (yuk yuk).

please don't respond with anything other than what i need to know. i do not
need to hear anything about re-design etc.

thanks much for your time and knowledge.
 
mcnews2k said:
what is the most reliable way to move to the last record + 1 when a form
loads. i tried using docmnd.gotorecord, acForm, "myform", aclast (whatever
the syntax is) and it worked sometinme but not always.
tried using me.recordsetclone as well with similar results.
i'm now using a global veriable that gets set when MDB opens or when a
record is added the the main table.
what i have are several 1 to 1 tables and forms. all tables get a record
added to them whenever the main table gets appended to. this always works
when i use the app, but of course users do everything wrong (yuk yuk).

please don't respond with anything other than what i need to know. i do not
need to hear anything about re-design etc.

Try looking at the help file for DoCmd.GoToRecord. You'll find that in
addition to an acLast argument, there is also an acNewRec argument you can
use.
 
mcnews,
Not sure what you mean by "last record + 1"... that would actually be a
New record.
DoCmd.GoToRecord , , acNewRec
If you look at any table, the next record after Last is New.

Since you say your acLast code "worked sometinme but not always", I
expect you have another problem... but since you don't want any advice in
that regard, I'll leave that to you.
 
Rick Brandt said:
Try looking at the help file for DoCmd.GoToRecord. You'll find that in
addition to an acLast argument, there is also an acNewRec argument you can
use.

tried that too.
 
Not sure what you mean by "last record + 1"... that would actually be a
New record.
DoCmd.GoToRecord , , acNewRec
If you look at any table, the next record after Last is New.

Since you say your acLast code "worked sometinme but not always", I
expect you have another problem... but since you don't want any advice in
that regard, I'll leave that to you.

tried the acNewRec too.

what was happening is that it would go to the 3rd or 4th record sometimes
and the last or newrec sometimes.

if you think you understand what i'm asking and have a solution of course
i'd be happy to hear from you.
was i was trying to avoid is advice from some of the newby know-it-alls you
hear from in these groups sometimes who try to give advice in the "perfect
world" or "bill gates says" it's supposed to be like this kind of thing.
 
The following command/s will open a form and move to a New record... It
is usually placed behind the button that opens the form.
DoCmd.OpenForm "YourFormName"
DoCmd.GoToRecord , , acNewRec

Also, DoCmd.GoToRecord , , acNewRec should work fine, whether called by
the FormLoad, or FormOpen events... if you're not using a button to open
the form. (just dbl-clicking the form name).

If that fails, or works erratically, then you have some other code that's
interfering with it.
 
mcnews2k said:
tried the acNewRec too.

what was happening is that it would go to the 3rd or 4th record sometimes
and the last or newrec sometimes.

I don't really understand this except for one possibility.
DoCmd.GoToRecord can be messed up by focus. Are you explicitly including
the object type and name in the command? If not it might erroneously get
applied to a different object if your form is not considered the "current
active object".

As an alternative try...

DoCmd.RunCommand acCmdRecordsGoToNew

I believe this command differs in that it applies to the object where the
code is running regardless of current focus.
 
The following command/s will open a form and move to a New record... It
is usually placed behind the button that opens the form.
DoCmd.OpenForm "YourFormName"
DoCmd.GoToRecord , , acNewRec

Also, DoCmd.GoToRecord , , acNewRec should work fine, whether called by
the FormLoad, or FormOpen events... if you're not using a button to open
the form. (just dbl-clicking the form name).

If that fails, or works erratically, then you have some other code that's
interfering with it.
--

thanks much.
i think the find button wizard is setting some screen focus that is
interferring.
 
Back
Top