Report printing problem

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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.
 
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)
 
Back
Top