VBA error on printing a report from a form

J

Jocamo

Private Sub Command64_Click()
On Error GoTo Err_Command64_Click

Dim stDocName As String

stDocName = "RPTactiveleadsheet"
DoCmd.OpenReport stDocName, acNormal
DoCmd.OpenReport "OverdueReminder",
acViewNormal, , "[CustomerID]=Forms"
![CustomersOverdue]![CustomerID]"

Exit_Command64_Click:
Exit Sub

Err_Command64_Click:
MsgBox Err.Description
Resume Exit_Command64_Clickv
 
D

Douglas J. Steele

Are we supposed to guess what the error message is you're getting (and, for
that matter, which statement is causing it?)

I don't know whether you cut-and-paste that into your message, or retyped
it. Nor do I know which lines are caused by word-wrap. However, the second
DoCmd.OpenReport looks incorrect: certainly, as presented, it won't even
compile due to your quotes.

Trying to avoid word-wrap, try:

DoCmd.OpenReport "OverdueReminder", _
acViewNormal, , _
"[CustomerID]=" & _
Forms![CustomersOverdue]![CustomerID]

assuming CustomerID is a numeric field, or

DoCmd.OpenReport "OverdueReminder", _
acViewNormal, , _
"[CustomerID]=" & Chr$(34) & _
Forms![CustomersOverdue]![CustomerID] & _
Chr$(34)

if it's text.
 
J

Jocamo

Sorry for not giving enough detail, I did cut-n-paste.
I did find & error in my typing.

I am trying to open a report in such a way that it
displays or prints a form's current record. At this point
it only opens the report but the fields are blank.

I have pasted a copy below:
(The Customer Id field is autonumber)

Private Sub Command68_Click()
If Forms![FORMleadsheet].Dirty = True Then Forms!
[FORMleadsheet].Dirty = False
DoCmd.OpenReport "RPTactiveleadsheet",
acViewPreview, , "[Customer ID]=Forms![FORMleadsheet]!
[Customer ID]"
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top