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!

Trying to Print on the Current Record on a Form?

Status
Not open for further replies.

Azie

Technical User
Aug 19, 2001
10
US
I have a form called Daily Revenues, in that form a field called Invoice #. I need to print out two copies. I need it to prinnt only on the current record on the form. I am using a command button on the form. The following is the code I have set up through the code building [Event] on the properties butoon of "Invoice Command Button":

Private Sub Print_Invoice_Click()

Dim strDocName As String
Dim strWhere As String
strDocName = "Invoice"
strWhere = "Invoice #" = " & Forms![Invoice #]"
DoCmd.OpenReport strDocName, acPreview, , strWhere


On Error GoTo Err_Print_Invoice_Click

Dim intCopies As Integer
For intCopies = 1 To 2
stDocName = "Invoice"
DoCmd.OpenReport stDocName, acPreview
Next

Exit_Print_Invoice_Click:
Exit Sub

Err_Print_Invoice_Click:
MsgBox Err.Description
Resume Exit_Print_Invoice_Click

End Sub

I am need real fimiliar with VB Code. I have attempted this many times it works...like one in 20 times and why only then I do not know. Please help....I am Stuck.
.............Thanks
 
Try this

[tt]
Private Sub Print_Invoice_Click()

Dim strDocName As String
Dim strWhere As String
Dim intCopies As Integer

strDocName = "Invoice"
strWhere = "[Invoice #]" = " & Me.[Invoice #]"
DoCmd.OpenReport strDocName, acPreview, , strWhere

On Error GoTo Err_Print_Invoice_Click

For intCopies = 1 To 2
DoCmd.OpenReport strDocName, acPreview, ,strWhere
Next intCopies

Exit_Print_Invoice_Click:
Exit Sub

Err_Print_Invoice_Click:
MsgBox Err.Description
Resume Exit_Print_Invoice_Click

End Sub
[/tt]

See if that works better for ya! Joe Miller
joe.miller@flotech.net
 
Or, try this.

Private Sub Print_Invoice_Click()

Dim strDocName As String
Dim strWhere As String
strDocName = "Invoice"
strWhere = "Invoice #" = " & Forms![Invoice #]"
DoCmd.OpenReport strDocName, acPreview, , strWhere
DoCmd.PrintOut , , , , 2

On Error GoTo Err_Print_Invoice_Click

Exit_Print_Invoice_Click:
Exit Sub

Err_Print_Invoice_Click:
MsgBox Err.Description
Resume Exit_Print_Invoice_Click

End Sub
 
I am sure I am closer now.....but there still must be something wrong with strWhere statements. It is giving me a blank invoice and not the current record. I am sure I am allot closer now.
 
Shoulda noticed this before:

strWhere = "[Invoice #] = " & Me.[Invoice #]

That should fix it. Sorry I missed it earlier! Joe Miller
joe.miller@flotech.net
 
Thanks for all your help...it works great.
I do have one other question on the same type of code. In fact it is almost identical code only with a report named Estimate. It screen previews with one copy. It all works great EXCEPT.....I need it to stay on the same record after the Preview or Print Function is Done. I do have a requery clause in the statements now. If that happens to make a difference. I do appreciate all the help and assistence I have had here.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top