Trying to Open Blank Form

F

fridayxiii

I have a form (frmProjectDetails) which I'd like to open w/all fields
blank. I added the following code:

Sub ShowNewRecord()
DoCmd.OpenForm "frmProjectDetails", acNormal
DoCmd.GoToRecord , , acNewRec
End Sub

but when opening the form I get an error and am taken to the VB window
to debug. I've tried variations of the above code, tried placing it
in different subs or events but to no avail. Any ideas on what I've
done wrong?

BTW this is a bound from in Access 2K3.

Thanx,
Brian
 
G

Guest

Your second line:
DoCmd.GoToRecord , , acNewRec
should be moved to the Load event of the form you are opening.
 
J

John W. Vinson

I have a form (frmProjectDetails) which I'd like to open w/all fields
blank. I added the following code:

Sub ShowNewRecord()
DoCmd.OpenForm "frmProjectDetails", acNormal
DoCmd.GoToRecord , , acNewRec
End Sub

but when opening the form I get an error and am taken to the VB window
to debug. I've tried variations of the above code, tried placing it
in different subs or events but to no avail. Any ideas on what I've
done wrong?

Try explicitly referencing the form:

Sub ShowNewRecord()
DoCmd.OpenForm "frmProjectDetails", acNormal
DoCmd.GoToRecord acForm, "frmProjectDetails", acNewRec
End Sub


What error message are you getting??

John W. Vinson [MVP]
 
K

Keith G Hicks

I know this is not exactly what you are looking for but as a suggestion, you
might want to turn off the newrec stuff on the form altogether. I've never
liked that and rarely use it in my applications. I prefer to have users add
new records via an unbound "add new customer" (or similar) form and then I
post the data to the table in code afterward opening the customer form with
that new row of data now showing. If there are no customers the first time
the user tries to open the customer form then I pop up the little unbound
form. I find that with that strategy it's easier for me to control (and
clearer to the end user) which fields are required. Like I said, just a
suggestion. Of course if the table does not have any required fields, then
that's another issue (and not a very good idea IMHO).

Keith
 

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