Command Button Add Code

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
try this

Private Sub Add_Receipt_Click()
On Error GoTo Err_Add_Receipt_Click

Me.Recordset.AddNew
Me!ReceiptNum = Nz(DMax("[ReceiptNum]", "[tblReceipt]")) + 1


Exit_Add_Receipt_Click:
Exit Sub


Err_Add_Receipt_Click:
MsgBox Err.Description
Resume Exit_Add_Receipt_Click
End Sub
 
I get the message "type mismatch"?

Is it possible that this stems from complete misunderstanding of how to
force the primary keys, i.e. ReceiptID (p/k, autonumber) to automatically
change to the Receipt Num in forms and reports. For instance, in my forms I
have combo boxes that select the ReceiptID, but the second column is
ReceiptNum. Which is great, but when I try and do other functions, etc. it
seems to always come back and bite me in the butt! I have tried making
queries that will result in aliasing the id to the name or num, but then it
won't let me input anything in the form because it says the datatype does not
match.

Thank you so much for coming to my rescue. Sometimes I feel like I am just
hitting up against a brick wall. Unfortunately, I am a "need to be shown"
rather than "read the book" type of learner and it is sometimes difficult in
these newsgroups because everyone seems to speak a different language than I
do.
 
there is a button named "SUBMIT" there, but before you
click that button you have to type first the numbers appeared at the
left
of that button to the textbox.

then after you clicked that it will display a "Please wait 16 seconds"
it will count down. wait until that displayed changed to ""download"
and click that download.

Hope i explained it to you clearly.
 
Sorry, but for some reason when I opened the zip file it was empty. It
finally did appear and I downloaded it fine and appreciate all your help.
Thanks.
 
Back
Top