Ivoice number in reports

eyalco

Registered User.
Local time
Today, 15:35
Joined
Jul 24, 2007
Messages
50
I'm usind the damx+1 function for creating the invoice number in the invoice form but when I print it, the report gives me the former number (before the dmax+1). What am I doing wrong pls?
Also, the report gives a different customer name that the 1 in the invoice. Why?
Thanks.
 
Are you making sure to save the record before running the invoice report? To force a save when clicking a button to open the invoice, put

DoCmd.RunCommand acCmdSaveRecord
 
Thanks for the quick response.
It doesn't work.
The whole command is on the report button:

Private Sub PRINT2_Click()
On Error GoTo Err_PRINT2_Click

Dim msgResult As VbMsgBoxResult 'Boolean

msgResult = MsgBox "are u sure u want to save?", vbYesNo, "Important!")
If msgResult = vbNo Then
DoCmd.CLOSE acForm, Me.NAME
Exit Sub
End If

If msgResult = vbYes Then


Dim stDocName As String
stDocName = "frm_copies"
DoCmd.OPENFORM stDocName, acNormal


Me.STATUS = "closed"
Me.IS_PRINTED = True
[INVOICE_NO] = Nz(DMax("[INVOICE_NO]", "TBL_INVOICE") + 1)

DoCmd.RunCommand acCmdSaveRecord (what u suggested and I added)

stDocName = "RPT_INVOICE"
DoCmd.OpenReport stDocName, acNormal


Exit_PRINT2_Click:
Exit Sub

Err_PRINT2_Click:
MsgBox Err.Description
Resume Exit_PRINT2_Click


End If
End Sub

What's wrong?
 
Well, it would look like you are creating the invoice number but not saving it within the record anywhere. You need to set it within the bound form, or get it to the table somehow as your report will be pulling the data for the last invoice number and since you aren't incrementing it within the table, the last record is the previous one.
 
Yes' that is another problem.
Why isn't it being saved in the table? what's wrong?
 
Yes' that is another problem.
Why isn't it being saved in the table? what's wrong?

You are creating the number but not assigning it correctly. A quick fix would be to do this:

...<shortened for brevity>

Me![INVOICE_NO] = Nz(DMax("[INVOICE_NO]", "TBL_INVOICE") + 1)

DoCmd.RunCommand acCmdSaveRecord
 

Users who are viewing this thread

Back
Top Bottom