Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report doesn't preview unless in debug mode 1

Status
Not open for further replies.

FoxProProgrammer

Programmer
Apr 26, 2002
967
US
Hi folks,

A VB program counts the number of records in a table that have a null part. If the count is greater than 0, a form displays the number of undefined parts and presents the user with three buttons: Print report, Preview report, Cancel. The code to count the number of null records and call the form is:

emptyPartno = DCount("*", "Part", "isnull([cpart])")

If emptyPartno > 0 Then
DoCmd.OpenForm "Export Error", , , , , acDialog, emptyPartno

Here is the code in the "Export Error" form's command button OnClick procedures.

Private Sub btnCancel_Click()
DoCmd.Close
End Sub

Private Sub btnPreview_Click()
DoCmd.OpenReport "Undefined Parts", acViewPreview
DoCmd.Close
End Sub

Private Sub btnPrint_Click()
DoCmd.OpenReport "Undefined Parts", acViewNormal
DoCmd.Close
End Sub

Here's what happens when I run the program and emptyPartno is greater than 0. The Export Error form pops up. If I click on the Preview button, the report doesn't display and the form "Export Error" remains visible and active (I can click any of the three buttons), as if the Docmd.Close statement didn't execute. If I set a breakpoint and step through the code, the report opens in preview mode, the DoCmd.Close statement executes, and the "Export Error" form closes like it should.

Any idea why this is happening?

Thanks a lot,

dz
 
The Docmd.close may be closing the report.
Is it supposed to close the form? If so, change the code to Docmd.close acForm, "Export Error"
 
Duh is me! You are right. I wrongly assumed that DoCmd.Close would default to the object that it was called from. I now have a new issue, but will start a new thread for it. Thanks a lot for your reply.

dz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top