Not able to print current record...

K

Kelvin

I'm trying to print a report based on the corrent record in the form.

I'm sure I've used this code before, but this time it seems to be acting
different then usual.
I don't get an error message, but it pops up a box with the "SlsId" above a
box when, if I type in the SlsID that's displayed, I get the proper data on
the report.

I have no idea why it pops up the dialog box, prompting me to enter the
SlsId...

Any help would be appreciated.

Kelvin

+++++++++++++++++++++++++++++++++++++
Private Sub PrintReport_Click()
On Error GoTo Err_PrintReport_Click
Dim stDocName As String
Dim strWhere As String
stDocName = "rpt_CommentReport"
strWhere = "[SlsId] = " & Me.[SlsId]
DoCmd.OpenReport stDocName, acPreview, "", strWhere
Exit_PrintReport_Click:
Exit Sub
Err_PrintReport_Click:
MsgBox Err.Description
Resume Exit_PrintReport_Click
End Sub
+++++++++++++++++++++++++++++++++++++
 
D

Doug Steele

A few possibilities.

First, are you positive that the dialog box says SlsId, and not some subtle
variation on that? If it's a variation, try correcting the field name you're
using in your code to match.

If you don't see a variation, what happens if you just hit Enter when
prompted, rather than keying in a value? If the report still works, odds are
you've got something in the report itself that's referring to a field
incorrectly.

Another possibility is that SlsId is a text field, and you're not passing it
a string in your VBA. If SlsId is a text field, use

strWhere = "[SlsId] = '" & Me.[SlsId] & "'"

where, exagerated for clarity, that's

strWhere = "[SlsId] = ' " & Me.[SlsId] & " ' "
 
K

Kelvin

Thanks Doug that was it.

SlsId is a text field.
It works perfect now.

Thanks for you help

Doug Steele said:
A few possibilities.

First, are you positive that the dialog box says SlsId, and not some
subtle
variation on that? If it's a variation, try correcting the field name
you're
using in your code to match.

If you don't see a variation, what happens if you just hit Enter when
prompted, rather than keying in a value? If the report still works, odds
are
you've got something in the report itself that's referring to a field
incorrectly.

Another possibility is that SlsId is a text field, and you're not passing
it
a string in your VBA. If SlsId is a text field, use

strWhere = "[SlsId] = '" & Me.[SlsId] & "'"

where, exagerated for clarity, that's

strWhere = "[SlsId] = ' " & Me.[SlsId] & " ' "




--
Doug Steele, Microsoft Access MVP



Kelvin said:
I'm trying to print a report based on the corrent record in the form.

I'm sure I've used this code before, but this time it seems to be acting
different then usual.
I don't get an error message, but it pops up a box with the "SlsId" above
a
box when, if I type in the SlsID that's displayed, I get the proper data
on
the report.

I have no idea why it pops up the dialog box, prompting me to enter the
SlsId...

Any help would be appreciated.

Kelvin

+++++++++++++++++++++++++++++++++++++
Private Sub PrintReport_Click()
On Error GoTo Err_PrintReport_Click
Dim stDocName As String
Dim strWhere As String
stDocName = "rpt_CommentReport"
strWhere = "[SlsId] = " & Me.[SlsId]
DoCmd.OpenReport stDocName, acPreview, "", strWhere
Exit_PrintReport_Click:
Exit Sub
Err_PrintReport_Click:
MsgBox Err.Description
Resume Exit_PrintReport_Click
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