DoCmd.GoToRecord question

  • Thread starter Slez via AccessMonster.com
  • Start date
S

Slez via AccessMonster.com

I have a command button that opens frmNoBidMain, which contains a subform
called frmNoBid. In the open event of frmNoBid is the following code:

Private Sub Form_Open(Cancel As Integer)
DoCmd.GoToRecord acDataForm, "frmNoBid", acNewRec
End Sub

My intent is that when you open frmNoBidMain, it takes you to the NEW record
in frmNoBid as opposed to the first record.

When I click the command button, I get an error message: Run-time error
'2489'; The object 'frmNoBid' isn't open.
Debugging highlights my DoCmd line. Clicking Help doesn't yield anything.

What is wrong with my code?
Thanks!
Slez
 
M

Marshall Barton

Slez said:
I have a command button that opens frmNoBidMain, which contains a subform
called frmNoBid. In the open event of frmNoBid is the following code:

Private Sub Form_Open(Cancel As Integer)
DoCmd.GoToRecord acDataForm, "frmNoBid", acNewRec
End Sub

My intent is that when you open frmNoBidMain, it takes you to the NEW record
in frmNoBid as opposed to the first record.

When I click the command button, I get an error message: Run-time error
'2489'; The object 'frmNoBid' isn't open.
Debugging highlights my DoCmd line. Clicking Help doesn't yield anything.

What is wrong with my code?


I always thought the Open event was too early to navigate.
Try using the Load event.

OTOH, if you know that you want to go to the new record
before opening the form, use the OpenForm method's Datamode
argument with acFormAdd so it only allows records to be
added.
 
M

missinglinq via AccessMonster.com

This appears to be the topic of the week, both here and on other fora. The
OpenForm event is the initialization of the physicals aspects of the form, i.
e. the way the form appears on screen. The Form_Load event is where data
comes on board. The form's Record Source is loaded, comboboxes are "filled",
defaults values, if any, are assigned, and so forth. Since the recordset
hasn't been loaded yet, you can't go to a new record.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 
S

Slez via AccessMonster.com

Thank you for the replies!

Changing it to the Load event yielded the same message.
I don't want to set the form so that records can only be added, because there
may be instances when we need to scrioll back to an existing record and make
an adjustment.

When you say "you can't go to a new record", does that mean that what I'm
trying to do is not reasonably possible?...or is there some other method of
accomplishing this?
Thanks again!
Slez
 
M

missinglinq via AccessMonster.com

What happens if you replace your code with simply:

DoCmd.GoToRecord , , acNewRec
 
S

Slez via AccessMonster.com

Hey...That works!
I guess sometimes simplifying resolves the issue.
Thanks so much for the help!
Slez
 
M

Marshall Barton

Slez said:
Changing it to the Load event yielded the same message.
I don't want to set the form so that records can only be added, because there
may be instances when we need to scrioll back to an existing record and make
an adjustment.

When you say "you can't go to a new record", does that mean that what I'm
trying to do is not reasonably possible?...or is there some other method of
accomplishing this?


Subforms are not really open, i.e. they are not added to the
Forms collection. Try removing the form name.
DoCmd.GoToRecord , , acNewRec

An alternative is to use:
RunCommand acCmdRecordsGoToNew

You may need to set the focus to a control on the subform so
those methods can figure out which form to work on.
 

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