Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ok button needs to move to the next record 1

Status
Not open for further replies.

gbuchman1

Technical User
Mar 8, 2010
60
US
I have added an OK button to an invoice form. Users enter invoices on this form. After entering an invoice on this form, I want the user to be able to click an OK button that not only saves the record, but also moves on to a new window where the user could enter the next invoice. My database works fine and I can see that the invoice is populating the InvoiceMaster and InvoiceDetails tables. So really the main problem is that the OK button, when clicked, does not move the user to a blank record where he or she could enter the next invoice. Here is the Event code that is presently in the properties of the OK button (name SaveInvoice):

Private Sub SaveInvoice_Click()
On Error GoTo Err_SaveInvoice_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit_SaveInvoice_Click:
Exit Sub

Err_SaveInvoice_Click:
MsgBox Err.Description
Resume Exit_SaveInvoice_Click

End Sub
Private Sub UndoInvoice_Click()
On Error GoTo Err_UndoInvoice_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

Exit_UndoInvoice_Click:
Exit Sub

Err_UndoInvoice_Click:
MsgBox Err.Description
Resume Exit_UndoInvoice_Click

End Sub
Private Sub DeleteInvoice_Click()
On Error GoTo Err_DeleteInvoice_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Exit_DeleteInvoice_Click:
Exit Sub

Err_DeleteInvoice_Click:
MsgBox Err.Description
Resume Exit_DeleteInvoice_Click

End Sub

(You will see that I also have a DeleteInvoice button. The OK button is called SaveInvoice.) I tried adding this code:

CODE

Private Sub Form_Load()
DoCmd.GoToRecord , , acNewRec
End Sub

When I added this, it did go to a new empty record, but I got an error loop that never ended and I had to restore from backup. Perhaps I added it in the wrong spot. Please assist me with this. Thanks.
 
Replace this:
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
with this:
Me.Dirty = False
DoCmd.GoToRecord , , acNewRec

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I did this and saved the code and the form. But when I reentered the form and entered a new record, I got:

Compile error: Syntax error.
 
And which line of code is highlighted ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Here is the chunk of code:

Me!Dirty = FalseDoCmd.GoToRecord,acNewRec

(I changed the Me. to Me! since the other Me's had the !)

Anyway, I realized that I also did not put the right break, so I edited it to be:

Me.Dirty = False
DoCmd.GoToRecord,acNewRec

That solved that syntax error, but now I have a different error, after saving the form and entering a new invoice and clicking the OK button:

MS Access: The object '5' isn't open.

Any clue what this could mean?
 
Ah ha! I caught my error. I corrected it and made the lines to be:

Me.Dirty = False
DoCmd.GoToRecord,,acNewRec

...then it worked! It saves the record and advances to the empty screen with the next invoice number. Beautiful!
I ommitted the comma in an attempt to correct the first problem. Thanks very much PHV for your great answer!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top