Print report from command button

  • Thread starter Thread starter Elizabeth
  • Start date Start date
E

Elizabeth

I am trying to add a button to a form that will print a report showing detail
from that particular form. I have written a report that will show all of the
information as it would be seen on the form screen. However, I am having
trouble getting it to print the information for just one job. I have set up
an event procedure as follows:

Private Sub Print_JobEntry_Click()
On Error GoTo Err_Print_JobEntry_Click

Dim MyWhereCondition As String

MyWhereCondition = "JobID" = " & Me.JobID"
DoCmd.OpenReport " JobEntryJobQuery ", acViewPreview, , MyWhereCondition

Exit_Print_JobEntry_Click:
Exit Sub

Err_Print_JobEntry_Click:
MsgBox Err.Description
Resume Exit_Print_JobEntry_Click

End Sub

I can get the report to come up, but it does not have any information on it.
It simply has the labels. I have tried both making the underlying query
have criteria showing only one job and having the query with no criteria.
Can anyone please give me any suggestions on how to fix this so that the
report will actually show the information?
 
It's a bit confusing when your report name looks more like a query name.

Assuming JobID is numeric, try remove two quote marks and then some spaces
around the report name:

Private Sub Print_JobEntry_Click()
On Error GoTo Err_Print_JobEntry_Click

Dim MyWhereCondition As String

MyWhereCondition = "JobID = " & Me.JobID
DoCmd.OpenReport "JobEntryJobQuery", acViewPreview, , MyWhereCondition

Exit_Print_JobEntry_Click:
Exit Sub

Err_Print_JobEntry_Click:
MsgBox Err.Description
Resume Exit_Print_JobEntry_Click

End Sub
 
I renamed the report to take out the query part of the name. I then took out
the spaces around the report name. That works fine except that I still have
a report with only headers. I tried deleting the quotations from the JobID,
but received a syntax error. The JobID is a combination of numeric and alpha
characters. Any other suggestions?
 
If the JobID field is text, try:

Private Sub Print_JobEntry_Click()
On Error GoTo Err_Print_JobEntry_Click

Dim MyWhereCondition As String
Dim strReportName as String
strReportName = "JobEntry....Whatever"
MyWhereCondition = "JobID = """ & Me.JobID & """"
DoCmd.OpenReport strReportName, acViewPreview, , MyWhereCondition

Exit_Print_JobEntry_Click:
Exit Sub

Err_Print_JobEntry_Click:
MsgBox Err.Description
Resume Exit_Print_JobEntry_Click

End Sub
 
Back
Top