Full Version: Open Form to New Record
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
snsd
Hi:

Simple question. I have a command button on a menu form that opens another form. See the code below. When the form opens, it always displays the first record. I want a blank new record to be displayed ready for data input. What do I add to my code to do so.

Thanks in advance for your help.

Dave

Code
____________
Private Sub cmdResponseReceivedLogging_Click()
On Error GoTo Err_cmdResponseReceivedLogging_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmReceivedLogging"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdResponseReceivedLogging_Click:
Exit Sub

Err_cmdResponseReceivedLogging_Click:
MsgBox Err.Description
Resume Exit_cmdResponseReceivedLogging_Click

End Sub
HunterOfTheShadows
I believe that setting the forms Data entry option to YES will do the trick..

HTH

-hunter
snsd
Thanks Hunter. Thought I was getting good at this program... Oh well.

Dave frown.gif
dannyseager
you could have also added

DoCmd.GoToRecord acDataForm, stDocName, acNewRec

to the command after the line to open the form.
snsd
OK. I switched the "data entry" option to YES - but now I'm not able to view records that I've already entered to the form. So, I got what I wanted but lost something I liked! In other words, I want to have the ability to view existing records in the form but when opening the form have it go to the "new record" input screen. Any further ideas?

Thanks,

Dave
snsd
Thanks Danny!!! Works perfect. You must have read my mind as you responded to the question I just posted as I was writing it.

Dave
dannyseager
you're welcome

Glad to help
HunterOfTheShadows
Dan's the man!!

You actually helped clear up a problem i was just starting to have with opening a new form for Data Entry!!!

Thanks from me as well

thumbup.gif

-hunter
snsd
Another question in regards to this issue....

When my database opens, I have an "autoexec" macro open this form. As with the command button question, how do I get a "blank form ready for input" to appear when I first open the database versus the first record in the database.

Thanks in advance.

Dave
HunterOfTheShadows
Dave,

Putting Danny's code in the On Load event of the form might do the trick. I haven't tested this yet though. try it and post back the result.

HTH

-hunter
snsd
Bingo! Great suggestion. Works great. Thank-you. Please let me know if I could have done it any differently. Dave

Here's what it looks like.

CODE
Private Sub Form_Load()
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmMasterInput"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord acDataForm, stDocName, acNewRec

End Sub
HunterOfTheShadows
I don't know if you need anything but the last line:

DoCmd.GoToRecord acDataForm, stDocName, acNewRec

put a single quote ' in front of the other lines close the VBA window, save the form and try to reload it to see if the single line will do it.

-hunter
snsd
Hunter:

I tried that and got a "Variable not defined error" on " stDocName". Any other ideas?

Dave
mhourie
Try

DoCmd.GoToRecord acDataForm, Me.Name, acNewRec
snsd
Works perfectly. Thanks for the help.

Dave
HunterOfTheShadows
sorry...mhourie is correct. That should be your variable error (me.name).

--hunter
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.