Open report with forms-data-entry

R

reidarT

When I open a report I use a form to limeit the amount of data on the
report.
It could be a date intervall.
I use:
Private Sub Report_Open(Cancel As Integer)
On Error GoTo Report_Open_Err

Dim strDocName As String
'DoCmd.ShowToolbar "Print Preview", acToolbarYes

strDocName = "frmFraTilDato"
blnOpening = True

DoCmd.OpenForm strDocName, , , , , acDialog

blnOpening = False

Report_Open_Exit:
Exit Sub

Report_Open_Err:
MsgBox "You have canceled the action !", vbInformation, conAppMelding
Resume Report_Open_Exit
End Sub

When I click the close button without entering data in the 'frmFraTilDato'
form I get an 'error' where I have to
cancel the parameters in the report-recordsource (Fromdate and ToDate)
How can I just close the report and the form without any questions?

reidarT
 
M

Marshall Barton

reidarT said:
When I open a report I use a form to limeit the amount of data on the
report.
It could be a date intervall.
I use:
Private Sub Report_Open(Cancel As Integer)
On Error GoTo Report_Open_Err

Dim strDocName As String
'DoCmd.ShowToolbar "Print Preview", acToolbarYes

strDocName = "frmFraTilDato"
blnOpening = True

DoCmd.OpenForm strDocName, , , , , acDialog

blnOpening = False

Report_Open_Exit:
Exit Sub

Report_Open_Err:
MsgBox "You have canceled the action !", vbInformation, conAppMelding
Resume Report_Open_Exit
End Sub

When I click the close button without entering data in the 'frmFraTilDato'
form I get an 'error' where I have to
cancel the parameters in the report-recordsource (Fromdate and ToDate)
How can I just close the report and the form without any questions?


This seems like a clumsy way to get the report query's
parameters.

Typically, this kind of thing is done in the form that opens
the report. This way the query would not use parameters and
instead the report would be filtered by using the OpenReport
method's WhereCondition argument. Very simple, localized
and efficient.

To continue pursuing the approach you have now, you will
have to add code the form, 'frmFraTilDato' , that prevents
it from closing. Then add more code to the report's open
event procedure to verify that acceptable parameters have
been entered and cancel the report if the parameters are
unacceptable. Finally, add code to the report's close event
to close the form.
 
M

Martin

Are you using actual parameters in the query that underlies your report or
references to the relevant fields on the form? I would normally use the
latter in the situation you describe where the Fromdate field in the query
would have a criterion of Forms!frmFraTilDato!Fromdate to refer to the From
Date field in the form (and the equivalent for the To Date).

If you are using references to the form, you may want to encase them in Nz
functions to stop any Null errors: Nz(Forms!frmFraTilDato!Fromdate, 0)

Hope that helps.
 

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