G
Guest
I have spent hours and hours looking at questions and responses in the
newsgroups, gone to MVPs websites, looked at a million sample databases, took
a complete course on SQL coding for the last two days, have sent questions to
the newsgroups and I still can't do it! The replies that people send me seem
so simple and yet I don't understand how or where to implement it. I have
taken course after course on Microsoft Access as well as VBA. I am now in
tears and ready to have a breakdown!
I have a database for expenses. I have a table named tblReceipt that has a
field ReceiptNum (text field). I have tried to add a command button to the
form that will add a new receipt. When I click on the this button, I want to
have it insert the next consecutive receipt number in the new record
automatically. The receipt numbers are 060001, 060002, 060003, etc. I have
the following code that I have totally screwed up. I am sure that it is
embarrassingly obvious that i have no clue what I am doing. Someone please
help??!! See the code which has led me around in circles for the last three
days. I am come to the conclusion that I am just not ever going to get the
concept of writing code.
Private Sub Add_Receipt_Click()
On Error GoTo Err_Add_Receipt_Click
Me!ReceiptNum.SetFocus
DoCmd.GoToRecord , acActiveDataObject, acLast
Me!ReceiptNum = Nz(DMax("[ReceiptNum]", "[tblReceipt]")) + 1
DoCmd.GoToRecord , , acNewRec
Exit_Add_Receipt_Click:
Exit Sub
Err_Add_Receipt_Click:
MsgBox Err.Description
Resume Exit_Add_Receipt_Click
End Sub
newsgroups, gone to MVPs websites, looked at a million sample databases, took
a complete course on SQL coding for the last two days, have sent questions to
the newsgroups and I still can't do it! The replies that people send me seem
so simple and yet I don't understand how or where to implement it. I have
taken course after course on Microsoft Access as well as VBA. I am now in
tears and ready to have a breakdown!
I have a database for expenses. I have a table named tblReceipt that has a
field ReceiptNum (text field). I have tried to add a command button to the
form that will add a new receipt. When I click on the this button, I want to
have it insert the next consecutive receipt number in the new record
automatically. The receipt numbers are 060001, 060002, 060003, etc. I have
the following code that I have totally screwed up. I am sure that it is
embarrassingly obvious that i have no clue what I am doing. Someone please
help??!! See the code which has led me around in circles for the last three
days. I am come to the conclusion that I am just not ever going to get the
concept of writing code.
Private Sub Add_Receipt_Click()
On Error GoTo Err_Add_Receipt_Click
Me!ReceiptNum.SetFocus
DoCmd.GoToRecord , acActiveDataObject, acLast
Me!ReceiptNum = Nz(DMax("[ReceiptNum]", "[tblReceipt]")) + 1
DoCmd.GoToRecord , , acNewRec
Exit_Add_Receipt_Click:
Exit Sub
Err_Add_Receipt_Click:
MsgBox Err.Description
Resume Exit_Add_Receipt_Click
End Sub