Report not printing

  • Thread starter Thread starter AHopper
  • Start date Start date
A

AHopper

On a form I have a command button that has the code below
in the On Click event. I am trying to print a report. I
have added a MsgBox to see what response I am
getting. "ReportDate" is a text box on the form formated
to 9/2/2004.
When I Click the button, the code seems to respond
correctly.
I get the first message box.
"Do you wan to print a day report for all jobs on the
selected date?"

When I respond "Yes" I do not get the second Message box
MsgBox "" & ReportDateCriteria & "" and I do not get a
printed report.

I use "" & ReportDateCriteria & "" three other times in
the same block of code with different If clauses, I get
the correct response and a printed report. The report
name is "rptRegisteredUniqueWeightSkidReport" "Shift"
and "JobNumber" are text boxes on the form.



I am trying to print a report for the selected day. The
other print options include Shift and/ or JobNumber. This
report appears to be the easiest one but I have not been
able to get it to print.

This is the code I have the problem with.

Dim stDocName As String
Dim ReportDateCriteria As String

stDocName = "rptRegisteredUniqueWeightSkidReport"

If IsDate(.ReportDate) And Nz(.Shift) < 1 And Nz
(.JobNumber) < 1 Then
Answer = MsgBox("Do you want to print a day report for
all jobs on the selected date?")
If Answer = vbYes Then
ReportDateCriteria = "[DatePacked] = " & Format
(.ReportDate, "\#mm/dd/yyyy\#")
MsgBox "" & ReportDateCriteria & ""
DoCmd.Hourglass True
DoCmd.Echo False
DoCmd.OpenReport stDocName, acNormal, ,
ReportDateCriteria
DoCmd.Hourglass False
DoCmd.Echo True
Exit Sub
End If

Thank you for your time and support.

Allan
 
Can you confirm that the query underlying your report functions properly
(i.e., returns expected rows) when you "hard code" a date into the
criterion?
 
Jeff,
If I open my report and put #9/02/2004# into the query
criteria, I do get the correct records for the report.
The failure seems to happen when I declare the variable.
The message box does not return a value, if fact the
message box does not appear. This means that there is no
criteria for the report to use. That is the part I don't
understand because in the same event I use the same
variable and it returns the correct date.

Thanks
Allan
 
Thank you for your help. I found what was wrong. I set up
the code for a Message Box vbYes or vbNo response but
only allowed for an vbOk answer.

Allan
 
Back
Top