DoCmd

J

John

Hi
I have a form "Selection"
A subform "Game"
On a Cmd button I'm trying to get Selection to go to a new
record but Game to go to first record. Game is a reference
tbl.Ive tried the following, and variations of but keep
being told that the form either doesn't exist or is not
open. In the Project pane I am can see both forms and the
correct spelling.I'm stuck. Any pointers appreciated

Private Sub CmdAdd_Click()
On Error GoTo Err_CmdAdd_Click

DoCmd.OpenForm "Me!Form!Selection!Game", acNormal
DoCmd.GoToRecord acDataForm, "Me!Form!Selection!Game",
acFirst

DoCmd.GoToRecord , , acNewRec

Exit_CmdAdd_Click:
Exit Sub
 
D

Dirk Goldgar

John said:
Hi
I have a form "Selection"
A subform "Game"
On a Cmd button I'm trying to get Selection to go to a new
record but Game to go to first record. Game is a reference
tbl.Ive tried the following, and variations of but keep
being told that the form either doesn't exist or is not
open. In the Project pane I am can see both forms and the
correct spelling.I'm stuck. Any pointers appreciated

Private Sub CmdAdd_Click()
On Error GoTo Err_CmdAdd_Click

DoCmd.OpenForm "Me!Form!Selection!Game", acNormal
DoCmd.GoToRecord acDataForm, "Me!Form!Selection!Game",
acFirst

DoCmd.GoToRecord , , acNewRec

Exit_CmdAdd_Click:
Exit Sub

Where is this command button? If it's on the form "Selection", and
"Game" is a linked subform on that form, then I think all you need is
this, without the other lines:

DoCmd.GoToRecord , , acNewRec

Does that not do what you want?
 
J

John

-----Original Message-----


Where is this command button? If it's on the form "Selection", and
"Game" is a linked subform on that form, then I think all you need is
this, without the other lines:

DoCmd.GoToRecord , , acNewRec

Does that not do what you want?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Yes the button is on the "selection" form. Using

DoCmd.GoToRecord , , acNewRec works for the "selection"
form, but the rest
DoCmd.OpenForm "Me!Form!Selection!Game", acNormal
was to get the subform"Game" reset back to the first record

John
 
D

Dirk Goldgar

John said:
DoCmd.GoToRecord , , acNewRec works for the "selection"
form, but the rest

was to get the subform"Game" reset back to the first record

I conclude that the subform is not linked to a field on the main form,
or else I'd expect it to automatically requery with each new main
record, placing it at the first record. This being the case, try this
for your button's click event:

DoCmd.GoToRecord , , acNewRec
Me!Game.SetFocus
DoCmd.GoToRecord , , acFirst

This will leave the focus in the subform. If you don't want that,
decide where on the main form you want the focus to be, and add another
line to set the focus there after the above lines.

Note: the above assumes that "Game" is the name of the subform
*control* on the main form, not just the name of the form object being
displayed by that control. It is the name of the subform control that
must be used in the SetFocus line above.
 

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