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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print a current record from a form

Status
Not open for further replies.

acnovice

Programmer
Jan 27, 2005
100
US
I have a little problem when I try to print a current record from the invoice form.
When I click the "Print Invoice", pop-up box showes up and it askes me "Enter Parameter Value. InvBase No".
I hit the Invoice No then report form shows up but not the current record. It brings the first record.

I need someone's help...

My code are following.

Private Sub prtInvoice_Click()
On Error GoTo Err_prtInvoice_Click

Dim stDocName, stWhere As String
stWhere = "[InvBaseNo]=[Forms]![frmInvoice]![InvBaseNo]"
stDocName = "rptInvoice"
DoCmd.OpenReport stDocName, acPreview, "", stWhere

Exit_prtInvoice_Click:
Exit Sub

Err_prtInvoice_Click:
MsgBox Err.Description
Resume Exit_prtInvoice_Click

End Sub
 


Try..
Code:
Private Sub prtInvoice_Click()
On Error GoTo Err_prtInvoice_Click

    Dim stDocName, stWhere As String
    stWhere = "[InvBaseNo]= " & [Forms]![frmInvoice]![InvBaseNo]
    stDocName = "rptInvoice"
    DoCmd.OpenReport stDocName, acPreview, "", stWhere

Exit_prtInvoice_Click:
    Exit Sub

Err_prtInvoice_Click:
    MsgBox Err.Description
    Resume Exit_prtInvoice_Click
    
End Sub

[thumbsup2]


 

There may be a syntax problem. Darn NOT at my machine...

or try...

Code:
  stWhere = "[InvBaseNo]= Forms!frmInvoice!InvBaseNo"

' or

  stWhere = "[InvBaseNo]" = me!InvBaseNo



 
I would remove the "" argument from the DoCmd.OpenReport methdo.

Assuming InvBaseNo is a numeric field in your report's record source:
Code:
Private Sub prtInvoice_Click()
On Error GoTo Err_prtInvoice_Click

    Dim stDocName [b]As String[/b], stWhere As String
    stWhere = "[InvBaseNo]= [b]" & [/b][Forms]![frmInvoice]![InvBaseNo]
    stDocName = "rptInvoice"
    DoCmd.OpenReport stDocName, acPreview, , stWhere

Exit_prtInvoice_Click:
    Exit Sub

Err_prtInvoice_Click:
    MsgBox Err.Description
    Resume Exit_prtInvoice_Click
    
End Sub

If the field [InvBaseNo] is text, substitute this line:
Code:
 stWhere = "[InvBaseNo]= [b]""" & [/b][Forms]![frmInvoice]![InvBaseNo] & [b]""""[/b]

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
HitechUser,

I tried all of them, but none of them works.
The result is same as before.
 
dhookom,

Yes "InvBaseNo" is numeric.
I removed argument "" from DoCmd.OpenReport but it's same result as I mentioned earlier.
 
Your first posting has InvBase No with a space while your code doesn't have a space.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
dhookom,

Right... that's the typo. My code is right. There's no space "InvBaseNo"
 
So is your issue resolved? Which was the typo: in your report or in your posting here?

If running your report prompts for a field value then the field name is not in your report's record source.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
dhookom,

You're right. I was using a field name "InvBaseNo" from the form not from the report's record source.

I used "Invoice_InvBaseNo" not "InvBaseNo"

So I changed to...
stWhere = "[Invoice_InvBaseNo]= " & [Forms]![frmInvoice]![InvBaseNo]

now, it works.
Thank you so much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top