print record in form. . .not working

P

Piperlynne

Hello,
I am using this code to allow users to print the current record on the form.
It is working for two of my other forms, but not this one. it keeps popping
up a parameter value box.

Private Sub cmdPrtProdSetupbyCust_Click()
Dim strWhere As String

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[Profitability_Code] = " & Me.[Profitability_Code]
DoCmd.OpenReport "rptProductSetupALL", acViewPreview, , strWhere
End If
End Sub

Profitability_Code is a number field. I have also tried it with the extra
quotes (i.e - strWhere = "[Profitability_Code] = """ &
Me.[Profitability_Code] & """")

Any clue as to why this is happening?

Any help appreciated. -
Thanks in advance.
 
D

Douglas J. Steele

Ensure that report can be opened by itself, not using the VBA. If it can't,
then odds are you've changed a field name, and the change hasn't been
replicated in the report.

Pay attention for what variable the prompt is looking: it may help pinpoint
the problem.
 
P

Piperlynne

Thank you! I knew I was overlooking something obvious.
Didn't have the field in the query for the report (been lots of revisions in
the last 2 days LOL) I feel dumb or tired.

Thanks again!

Douglas J. Steele said:
Ensure that report can be opened by itself, not using the VBA. If it can't,
then odds are you've changed a field name, and the change hasn't been
replicated in the report.

Pay attention for what variable the prompt is looking: it may help pinpoint
the problem.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Piperlynne said:
Hello,
I am using this code to allow users to print the current record on the
form.
It is working for two of my other forms, but not this one. it keeps
popping
up a parameter value box.

Private Sub cmdPrtProdSetupbyCust_Click()
Dim strWhere As String

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[Profitability_Code] = " & Me.[Profitability_Code]
DoCmd.OpenReport "rptProductSetupALL", acViewPreview, , strWhere
End If
End Sub

Profitability_Code is a number field. I have also tried it with the extra
quotes (i.e - strWhere = "[Profitability_Code] = """ &
Me.[Profitability_Code] & """")

Any clue as to why this is happening?

Any help appreciated. -
Thanks in advance.
 

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