Report printing problem

G

Guest

I have a command button to print a report:
Private Sub Command85_Click()
On Error GoTo Err_Command85_Click
Dim stDocName As String
stDocName = "allclientsvaluesforcalculation"
DoCmd.OpenReport stDocName, acNormal
Exit_Command85_Click:
Exit Sub
Err_Command85_Click:
MsgBox Err.Description
Resume Exit_Command85_Click
End Sub

How can I change the code so, that it is asking for which salespersonid i
would like to print the report (I do not want to print the report always for
all salespersons)?
Thanks for your help.
Klaus
 
A

Arvin Meyer [MVP]

Change it to look like this:

Private Sub Command85_Click()
On Error GoTo Err_Command85_Click
Dim stDocName As String
Dim strCriteria As String

strCriteria = "[SalespersonID]=" & "'" & Me![txtSalespersonID] & "'"
stDocName = "allclientsvaluesforcalculation"

DoCmd.OpenReport stDocName, acNormal, , strCriteria
Exit_Command85_Click:
Exit Sub
Err_Command85_Click:
MsgBox Err.Description
Resume Exit_Command85_Click
End Sub

Where txtSalesPersonID is the name of the textbox on your form that holds
the SalesPersonID field's data.
 
D

Douglas J. Steele

Private Sub Command85_Click()
On Error GoTo Err_Command85_Click

Dim stDocName As String
Dim stSalespersonID As String

stDocName = "allclientsvaluesforcalculation"
stSalespersonID = InputBox("What Salesperson ID?")

If Len(stSalesPersonID) > 0 Then
DoCmd.OpenReport stDocName, acNormal, , _
"salespersonid = " & stSalespersonID
Else
DoCmd.OpenReport stDocName, acNormal
End If

Exit_Command85_Click:
Exit Sub
Err_Command85_Click:
MsgBox Err.Description
Resume Exit_Command85_Click
End Sub


That assumes that salespersonid is a numeric field. If it's text, you'll
need to use

"salespersonid = """ & stSalespersonID & """"

(that's three double quotes in front, and four double quotes after)
 

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