Report preview problem

  • Thread starter Thread starter Andy
  • Start date Start date
A

Andy

Hi

I have a form named Estimates and I am trying to add a
control button to preview the report estimates. The
button works fine but only previews the 1st Estimate. In
the report query I have entered criteria so that it asks
for an Estimate number. This works when you open the
report independently but won't work when I want to
preview the report from the command button on the form
itself, it doesn't ask for the Estimate number.

Any idea of what code I need to preview a report on the
current record showing on the form.

Thanks

Andy
 
The way I handle this is add a text box to your form where
the user enters the estimate number he wants to see.

In the source query for the report, for the EstimateNumber
field, use "[Forms]![frmEstimates]![txtEstimateNo]" as
your criteria.

For the code behind your command button use:

Private Sub cndPrintEstimate_Click()

' confirm an estimate number has been entered
If IsNull([txtEstimateNo]) Or [txtEstimateNo] = "" Then
MsgBox "You forgot to enter the estimate to print",
vbOKOnly, "Oops!"
[txtEstimateNo].SetFocus
Exit Sub
End If

' print report
DoCmd.OpenReport "rptReportName", acViewPreview

End Sub

Now, it will run from the form without having to ask you
for the estimate number. You'll still need to enter it if
you run the report directly from the database window.

Hope this helps!

Howard Brody
 
I don't know if this is the best solution, but I have used
a parameter as a part of a macro to print a report based
on selected information. The macro was OpenReport. The
arguments were the report name, and the Where Condition
below.

[query name]![Field name]=[Enter line item]

Ken Allen
 
Howard

Many thanks this works just fine.

Andy
-----Original Message-----
The way I handle this is add a text box to your form where
the user enters the estimate number he wants to see.

In the source query for the report, for the EstimateNumber
field, use "[Forms]![frmEstimates]![txtEstimateNo]" as
your criteria.

For the code behind your command button use:

Private Sub cndPrintEstimate_Click()

' confirm an estimate number has been entered
If IsNull([txtEstimateNo]) Or [txtEstimateNo] = "" Then
MsgBox "You forgot to enter the estimate to print",
vbOKOnly, "Oops!"
[txtEstimateNo].SetFocus
Exit Sub
End If

' print report
DoCmd.OpenReport "rptReportName", acViewPreview

End Sub

Now, it will run from the form without having to ask you
for the estimate number. You'll still need to enter it if
you run the report directly from the database window.

Hope this helps!

Howard Brody

-----Original Message-----
Hi

I have a form named Estimates and I am trying to add a
control button to preview the report estimates. The
button works fine but only previews the 1st Estimate. In
the report query I have entered criteria so that it asks
for an Estimate number. This works when you open the
report independently but won't work when I want to
preview the report from the command button on the form
itself, it doesn't ask for the Estimate number.

Any idea of what code I need to preview a report on the
current record showing on the form.

Thanks

Andy
.
.
 
Back
Top