Form vs. Report - what am I looking at?

Z

zSplash

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? (?)

TIA
 
A

Allen Browne

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.
 
Z

zSplash

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

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