Message Yes/No to proceede to next record or close form

K

Ktowner

I have a Database (Access 07) that I put to gather and use to help manage a
large equipment fleet for the DOT. I have never had any formal training in
Access but through trial and error and exploring sample databases have built
a very useful DB.

My Form is used for entering records. Could anyone help with the code for a
submit button that would prompt a message “Would You Like To Enter Another
Record†that would then go to a new record or close the form.

Thanks in advance

Don K.
 
M

Mr. B

Ktowner,

Place the following code in the On Click event of the button on your form:

Dim strMsg as String
Dim vbResponse

Dim strMsg As String
Dim vbResponse

strMsg = "Would You Like To Enter Another Record?"
vbResponse = MsgBox(strMsg, vbYesNo + vbDefaultButton2 + vbQuestion, _
"Create New Record?")
If vbResponse = vbYes Then
DoCmd.GoToRecord acDataForm, , acNewRec
Else
DoCmd.Close acForm, "NameOfYourForm"
End If

-----
HTH
Mr. B
http://www.askdoctoraccess.com/
Doctor Access Downloads Page:
http://www.askdoctoraccess.com/DownloadPage.htm
 
K

Ktowner

Thanks Mr. B

Almost there. When using the code you provided, it works great with option
"No". The form closes back to my forms switchboard.

But when I select option "Yes", I get a "Run-time error 2493.
When clicking Debug I get the following

Private Sub Enter_Next_350_or_354_Click()
Dim strMsg As String
Dim vbResponse

strMsg = "Would You Like To Enter Another Record?"
vbResponse = MsgBox(strMsg, vbYesNo + vbDefaultButton2 + vbQuestion, _
"Create New Record?")
If vbResponse = vbYes Then
DoCmd.GoToRecord acDataForm, , acNewRec
Else
DoCmd.Close acForm, "Area Shop Workload New 350"
End If

The following line is highlighted
DoCmd.GoToRecord acDataForm, , acNewRec

Thanks

Ktowner
 
K

Ktowner

Also I was wanting to know if i could accomplish the same thing without the
"submit" button. Could the code be tied to the last data field of the record
so that hitting the tab or enter key on the last field would trigger the
event.

Thanks Again
 
K

Ktowner

Under the Run-time error 2493 there is a statement "This action requirs an
Object Name argument

Sorry, I did not include this with the eariler post.
 
M

Mr. B

Sorry, I just created the code incorrectly. The line that is causing the
error should be:
DoCmd.GoToRecord , , acNewRec

If you use it as above it assumes the current form. Check out the Help file
for more info.

As for your question about the requirement for haveing to have the "submit"
button, you could use the same code in the After Update event of the control
where your users are entering data.

-----
HTH
Mr. B
http://www.askdoctoraccess.com/
Doctor Access Downloads Page:
http://www.askdoctoraccess.com/DownloadPage.htm
 

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