Form vs. Report - what am I looking at?

Form vs. Report - what am I looking at?

Post by zSplas » Sat, 31 Mar 2007 05:35:02

I've created a "parameterForm" to allow me to get input. So, I open the
"pForm", get input, then open the query, open the report, close the query,
close the "pForm".

The screen output looks fine -- the value for the textbox related to the
parameter query/form is 45; when I print the report, however, it prints an
"#Error" for the value.

A clue (which I can't decipher) might be the following: I have a label in
the report that I "fill" from VBA, based on the value of a textbox in the
parameterForm; I have no such label on the form; what I see on the screen
does not "fill" the label, but the printed report has the label caption.
Maybe I'm not looking at the report on the screen, but at the form (which I
never opened, but from which I created the report).

Here is my VBA code:
Private Sub cmbOK_Click()
Dim closeIt As Integer, theTerm As String
DoCmd.OpenQuery ("yqCUS")
DoCmd.OpenReport "rStats", acViewPreview
theTerm = Application.Forms("fgetStats").Controls("tbxBegDate") & " - "
& Application.Forms("fgetStats").Controls("tbxEndDate")
Application.Reports("rStats").Controls("labTerm").Caption = theTerm
DoCmd.Close acQuery, "yqCUS", acSaveNo
DoCmd.Close acForm, "fGetStats", acSaveNo
DoCmd.PrintOut acPrintAll
closeIt = MsgBox("Close report?", vbYesNo, "Close report?")
If closeIt = 6 Then
DoCmd.Close acReport, "rStats", acSaveNo
End If
End Sub

Can somebody help me understand the discrepancy between what I see and what
I print? (?)


Form vs. Report - what am I looking at?

Post by Allen Brow » Sat, 31 Mar 2007 10:52:31

If the report's query is reading the value from the form, you must leave the
form open until the report is finished with it.

An alternative approach might be to use the WhereCondition of OpenReport, so
it passes values to the report's Filter instead of having the report's query
refer to the form.

Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users -
Reply to group, rather than allenbrowne at mvps dot org.


Form vs. Report - what am I looking at?

Post by zSplas » Sun, 01 Apr 2007 01:52:21

Perfect! Moved the print report line to before closing the form, and --
problem solved!
Thanks, Allen.