Go to a new record on another form?

B

BonnieW

Hello!
I have a form (Form2) which is being opened (or sometimes set focus to) from
another form (Form1). On the open and gotfocus events, I want it to go to a
new record; however, I also want it to be able to see/edit previous records
(so the DataEntry mode option is right out).

-I have no OnGotFocus, OnLoad, etc events in Form2

-the code on Form1 calling Form2 is on a command button. I've included the
whole mess of code on that button, just in case I'm missing something
dreadfully obvious:

Private Sub Command28_Click()
'the "record the valiant effort of this volunteer" button

On Error GoTo Err_Command28_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmVolEffortGen"


'check to see that a name is actually selected
If IsNull(Me!LastName) Then
MsgBox "Choose a volunteer, or create a new one."
Cancel = True
Me!Combo26.SetFocus
'if frmVolEffortGen is loaded
ElseIf CurrentProject.AllForms("frmVolEffortGen").IsLoaded Then
'update the control with names
Forms![frmVolEffortGen].Requery
'go to the form...
Forms![frmVolEffortGen].SetFocus
'DoCmd.GoToRecord , frmVolEffortGen, acNewRec
DoCmd.GoToRecord , , acNewRec
'DoCmd.GoToRecord , , acLast, 1

'Forms![frmVolEffortGen]![VolName].Requery

Else
'open the form (@newrecord), set focus to a control
DoCmd.OpenForm "frmVolEffortGen"
DoCmd.GoToRecord , , acNewRec
'DoCmd.GoToRecord , , acLast, 1
'DoCmd.GoToControl "EffortDate"
End If


Exit_Command28_Click:
Exit Sub

Err_Command28_Click:
MsgBox Err.Description
Resume Exit_Command28_Click

End Sub


Thanks in advance for any help you can offer. You all have been most helpful
in the past. :)
 
J

John W. Vinson

DoCmd.GoToRecord , , acNewRec

make this explicit and you should be OK:

DoCmd.GoToRecord acDataForm, "frmVolEffortGen", acNewRecord

By default it will go to the new record of the *active* form - the one you're
calling from.

John W. Vinson [MVP]
 
B

BonnieW via AccessMonster.com

Unfortunately, now it's giving me the error message "You can't go to the
specified record." The form properties of frmVolEffortGen are set to allow
additions, deletions, edits, etc. Is there any other reason I'd be unable to
go to the new record?

Thanks!
Bonnie
 
B

BonnieW via AccessMonster.com

I should perhaps also add- by using the built-in record navigation buttons at
the bottom of the screen, I can get to the new record without any fuss.
Currently the code kicks me to the first record in the table, however. There
are four subforms on the form that I'm trying to open; the only event
associated with them or the objects they contain (combo boxes) is an OnExit
event meant to pop you to the next field in the form.
 
B

BonnieW via AccessMonster.com

Annnnd... (sorry for all the additions, but I'm really not sure what's
helpful at this point): it's a bound form; the table it's writing to has an
AutoNumber as the primary key that is displayed by the form.
I should perhaps also add- by using the built-in record navigation buttons at
the bottom of the screen, I can get to the new record without any fuss.
Currently the code kicks me to the first record in the table, however. There
are four subforms on the form that I'm trying to open; the only event
associated with them or the objects they contain (combo boxes) is an OnExit
event meant to pop you to the next field in the form.
[quoted text clipped - 6 lines]
John W. Vinson [MVP]
 
J

John W. Vinson

Unfortunately, now it's giving me the error message "You can't go to the
specified record." The form properties of frmVolEffortGen are set to allow
additions, deletions, edits, etc. Is there any other reason I'd be unable to
go to the new record?

Thanks!
Bonnie

Sorry, Bonnie - I'm baffeled! This works for me.

John W. Vinson [MVP]
 
B

BonnieW via AccessMonster.com

Thanks for trying anyway! :)
Unfortunately, now it's giving me the error message "You can't go to the
specified record." The form properties of frmVolEffortGen are set to allow
[quoted text clipped - 12 lines]
Sorry, Bonnie - I'm baffeled! This works for me.

John W. Vinson [MVP]
 

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