opening form to New Record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a People form that shows allows editting of info in my People table
(name, email, cellphone, etc.), and a button that allows the user to open the
Volunteer form to show the Volunteer Record for this person.

But I can't create a button to open the Volunteer Form to a new record.

Code that's not working:
stDocName = "Volunteer"
DoCmd.OpenForm stDocName
DoCmd.GoToRecord acDataForm, stDocName, acNewRec

the message I get is "You can't go to the specified record"

I will need to set the value of Volunteer.[People ID] to the value of
People.[People ID] in the new record.

Could someone explain why this isn't working and how to correct?

thanks again, Amanda
 
This line:
DoCmd.GoToRecord acDataForm, stDocName, acNewRec
should be in the Volunteer Form Load Event. Where you are doing it is too
soon. The form is not yet enstantiated.
 
Amanda said:
I have a People form that shows allows editting of info in my People table
(name, email, cellphone, etc.), and a button that allows the user to open the
Volunteer form to show the Volunteer Record for this person.

But I can't create a button to open the Volunteer Form to a new record.

Code that's not working:
stDocName = "Volunteer"
DoCmd.OpenForm stDocName
DoCmd.GoToRecord acDataForm, stDocName, acNewRec

the message I get is "You can't go to the specified record"

I will need to set the value of Volunteer.[People ID] to the value of
People.[People ID] in the new record.


Another way is to open the form without existing records so
only the new record is displayed:

DoCmd.OpenForm stDocName, DataMode:=acFormAdd
 
Marshall,

That worked!, although it's a bit of a mystery to me why acFormAdd worked,
but not acNewRec. Is there a way to add code to this open form, add to
assign default vaues to the fields (so that the new Volunteer record
automatically has the correct People ID value)?

Thanks! Amanda

Marshall Barton said:
Amanda said:
I have a People form that shows allows editting of info in my People table
(name, email, cellphone, etc.), and a button that allows the user to open the
Volunteer form to show the Volunteer Record for this person.

But I can't create a button to open the Volunteer Form to a new record.

Code that's not working:
stDocName = "Volunteer"
DoCmd.OpenForm stDocName
DoCmd.GoToRecord acDataForm, stDocName, acNewRec

the message I get is "You can't go to the specified record"

I will need to set the value of Volunteer.[People ID] to the value of
People.[People ID] in the new record.


Another way is to open the form without existing records so
only the new record is displayed:

DoCmd.OpenForm stDocName, DataMode:=acFormAdd
 
Using the go to new record action immediately after
executing OpenForm is too soon. The OpenForm arguments are
integrated into the opening process. These are very
different actions and can not be thought of as alternative
ways of doing the same thing.

To pass the people id to the volunteer form, use the
OpenForm method's OpenArgs argument so the volunteer form
can set its own defaults.

DoCmd.OpenForm stDocName, _
DataMode:= acFormAdd, _
OpenArgs:= Me.[People ID]

Then add this to the Volunteer form's Open event procedure
(assuming the people id is a numeric type field):

Me.[people id text box name].DefaultValue = Me.OpenArgs
--
Marsh
MVP [MS Access]


Amanda said:
That worked!, although it's a bit of a mystery to me why acFormAdd worked,
but not acNewRec. Is there a way to add code to this open form, add to
assign default vaues to the fields (so that the new Volunteer record
automatically has the correct People ID value)?


Marshall Barton said:
Amanda said:
I have a People form that shows allows editting of info in my People table
(name, email, cellphone, etc.), and a button that allows the user to open the
Volunteer form to show the Volunteer Record for this person.

But I can't create a button to open the Volunteer Form to a new record.

Code that's not working:
stDocName = "Volunteer"
DoCmd.OpenForm stDocName
DoCmd.GoToRecord acDataForm, stDocName, acNewRec

the message I get is "You can't go to the specified record"

I will need to set the value of Volunteer.[People ID] to the value of
People.[People ID] in the new record.


Another way is to open the form without existing records so
only the new record is displayed:

DoCmd.OpenForm stDocName, DataMode:=acFormAdd
 
Back
Top