Event Procedure to print Invoice

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have placed a Control on the Main Form to Print an Invoice for the
displayed record. The "On Click" Event procedure is as follows:
Private Sub PRINT_INVOICE_Click()
On Error GoTo Err_PRINT_INVOICE_Click

Dim stDocName As String
Dim stCriteria As String
stDocName = "Invoice"
stCriteria = "Invoice Number =" & Me.Invoice_Number
DoCmd.OpenReport stDocName, acPreview, , stCriteria

Exit_PRINT_INVOICE_Click:
Exit Sub

"Invoice Number" is the Table's primary key field and is an Autonumber type.
The problem is that when I click on the control to print the displayed
record, i receive the following error:
"Syntax error (missing operator) in query expression '(Invoice Number = 1)'"

If I am on say record 2 (ie Invoice Number 2) the message is as above, but
refers to '(Invoice Number =2)'

Any help would be greatly appreciated to solve this problem
Thank You
 
Your field name contains a space, so you must enclose it in square brackets.

Try:
stCriteria = "[Invoice Number] =" & Me.Invoice_Number

BTW, it might be a good idea to save the record before printing, by adding
this line:
RunCommand acCmdSaveRecord
 
Thank you Allen for your advices. I added the line "RunCommand
acCmdSaveRecord" after the event procedure, but when I click to display the
Invoice the message says:
"The Command or action 'SaveRecord' isn't available now".
Can you solve this please?
and BTW Thank You very much

Allen Browne said:
Your field name contains a space, so you must enclose it in square brackets.

Try:
stCriteria = "[Invoice Number] =" & Me.Invoice_Number

BTW, it might be a good idea to save the record before printing, by adding
this line:
RunCommand acCmdSaveRecord

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Roger Bell said:
I have placed a Control on the Main Form to Print an Invoice for the
displayed record. The "On Click" Event procedure is as follows:
Private Sub PRINT_INVOICE_Click()
On Error GoTo Err_PRINT_INVOICE_Click

Dim stDocName As String
Dim stCriteria As String
stDocName = "Invoice"
stCriteria = "Invoice Number =" & Me.Invoice_Number
DoCmd.OpenReport stDocName, acPreview, , stCriteria

Exit_PRINT_INVOICE_Click:
Exit Sub

"Invoice Number" is the Table's primary key field and is an Autonumber
type.
The problem is that when I click on the control to print the displayed
record, i receive the following error:
"Syntax error (missing operator) in query expression '(Invoice Number =
1)'"

If I am on say record 2 (ie Invoice Number 2) the message is as above, but
refers to '(Invoice Number =2)'

Any help would be greatly appreciated to solve this problem
Thank You
 
Roger, this is what I personally use to save the record:
If Me.Dirty Then
Me.Dirty = False
End If

Note that you only include this for a bound form: otherwise the form does
not have a record to be saved.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Roger Bell said:
Thank you Allen for your advices. I added the line "RunCommand
acCmdSaveRecord" after the event procedure, but when I click to display
the
Invoice the message says:
"The Command or action 'SaveRecord' isn't available now".
Can you solve this please?
and BTW Thank You very much

Allen Browne said:
Your field name contains a space, so you must enclose it in square
brackets.

Try:
stCriteria = "[Invoice Number] =" & Me.Invoice_Number

BTW, it might be a good idea to save the record before printing, by
adding
this line:
RunCommand acCmdSaveRecord


Roger Bell said:
I have placed a Control on the Main Form to Print an Invoice for the
displayed record. The "On Click" Event procedure is as follows:
Private Sub PRINT_INVOICE_Click()
On Error GoTo Err_PRINT_INVOICE_Click

Dim stDocName As String
Dim stCriteria As String
stDocName = "Invoice"
stCriteria = "Invoice Number =" & Me.Invoice_Number
DoCmd.OpenReport stDocName, acPreview, , stCriteria

Exit_PRINT_INVOICE_Click:
Exit Sub

"Invoice Number" is the Table's primary key field and is an Autonumber
type.
The problem is that when I click on the control to print the displayed
record, i receive the following error:
"Syntax error (missing operator) in query expression '(Invoice Number =
1)'"

If I am on say record 2 (ie Invoice Number 2) the message is as above,
but
refers to '(Invoice Number =2)'

Any help would be greatly appreciated to solve this problem
Thank You
 
Back
Top