My form always closes when the report opens

  • Thread starter Thread starter M Skabialka
  • Start date Start date
M

M Skabialka

A long time ago I set up a form where the user enters one time information,
then pushes a button to print a report. As the report opens, the form
closes, so if he wants to change the info and print again, or even print the
same info again, he has to open the form again and enter the info again.

The problem is, I can't find code anywhere that tells the form to close when
the report opens. The only code on the report handles On No Data.

It doesn't matter whether I open the report from the form, or from the
database window, the form closes. There doesn't seem to be any code on the
form either except error handling for missing data, and opening the report.

Where can this vital piece of code be hiding so I can take it away!

Thanks,
Mich
 
M Skabialka said:
A long time ago I set up a form where the user enters one time
information, then pushes a button to print a report. As the report
opens, the form closes, so if he wants to change the info and print
again, or even print the same info again, he has to open the form
again and enter the info again.

The problem is, I can't find code anywhere that tells the form to
close when the report opens. The only code on the report handles On
No Data.

It doesn't matter whether I open the report from the form, or from the
database window, the form closes. There doesn't seem to be any code
on the form either except error handling for missing data, and
opening the report.

Where can this vital piece of code be hiding so I can take it away!

Assuming you've carefully examined the report's class module and
verified that there is no other code in it, there are still these
possibilities:

1. A macro being executed from one of the report's events

2. A call to a public function (e.g, "=CloseForm('frmRptParms')")
executed from one of the report's events.
 
I added the following code to the report:
Private Sub Report_Close()
Me.Visible = True
End Sub

Now I can close the report from the close button or the X in the corner and
the form stays open, but as soon as I open the report in design mode, the
form disappears or closes. All of the code on the report validates entries
on the form; or closes it when the close button is selected. Nothing else
tells it to become invisible or close.

1) I have never used macros and there aren't any in this or any database I
have created.

2) There are no calls to any functions in this report's code. Here's the
entire report code module:
Option Compare Database
Option Explicit
Private Sub Report_NoData(Cancel As Integer)
MsgBox "There is no data for this report. Cancelling report..."
Cancel = -1
End Sub
Private Sub Report_Close()
Me.Visible = True
[DoCmd].[Restore]
End Sub

Any other ideas about why my form closes when I go into design mode on the
report?

Thanks,
Mich
 
M Skabialka said:
I added the following code to the report:
Private Sub Report_Close()
Me.Visible = True
End Sub

Now I can close the report from the close button or the X in the
corner and the form stays open, but as soon as I open the report in
design mode, the form disappears or closes. All of the code on the
report validates entries on the form; or closes it when the close
button is selected. Nothing else tells it to become invisible or
close.

1) I have never used macros and there aren't any in this or any
database I have created.

2) There are no calls to any functions in this report's code. Here's
the entire report code module:
Option Compare Database
Option Explicit
Private Sub Report_NoData(Cancel As Integer)
MsgBox "There is no data for this report. Cancelling report..."
Cancel = -1
End Sub
Private Sub Report_Close()
Me.Visible = True
[DoCmd].[Restore]
End Sub

Any other ideas about why my form closes when I go into design mode
on the report?

Thanks,
Mich

This is getting odder and odder. In the first place, this code you
added ...
Private Sub Report_Close()
Me.Visible = True
End Sub

.... should have no effect whatever on the form. In the report's code
module, the "Me" keyword refers to the report, not the form. So I can't
understand why that code would make any difference to what's going on.
Yet you say it does. Very odd.
2) There are no calls to any functions in this report's code. Here's

That's not what I was referring to when I suggested "a call to a public
function (e.g, "=CloseForm('frmRptParms')") executed from one of the
report's events." This sort of call isn't made from the report's code
module, but from the properties of the report itself. If this
techniques is being used, then if you open the report's property sheet
in design view and look on the Event tab, on one of the event property
lines you'll see a function expression similar to the example I gave --
an equals sign followed by a function name, possibly with arguments
specified inside the parentheses. But if you look at the event
properties and see nothing but "[Event Procedure" (on the On Close and
On No Data lines), this isn't what's going on.

If there's nothing on the report, the only other thing I can think of is
something on the form, but it sure didn't sound like it. Would you care
to post the contents of the form's code module, too?
 
It's long - but here it is:

=======================================================
Option Compare Database
Option Explicit

Private Sub Combo61_AfterUpdate()
'** Place employee data from combo into fields as shown
Dim f As Form
Set f = Forms![Request for Visit Cancellation]
f![FullName] = f!Combo61.Column(2) + " " + f!Combo61.Column(1)
f![Social Security #] = f!Combo61.Column(4)
f![BirthDate] = f!Combo61.Column(6)
f![Birth City] = f!Combo61.Column(8)
f![Birth StateOrProvince] = f!Combo61.Column(9)
f![Birth PostalCode] = f!Combo61.Column(10)
f![Birth Country] = f!Combo61.Column(11)

End Sub
----------------------------------------
Private Sub FindAddress_AfterUpdate()
'**Place predefined address into fields as shown
Forms![Request for Visit Cancellation]![Address1] = Forms![Request for
Visit Cancellation]!FindAddress.Column(1)
Forms![Request for Visit Cancellation]![Address2] = Forms![Request for
Visit Cancellation]!FindAddress.Column(2)
Forms![Request for Visit Cancellation]![Address3] = Forms![Request for
Visit Cancellation]!FindAddress.Column(3)
Forms![Request for Visit Cancellation]![Address4] = Forms![Request for
Visit Cancellation]!FindAddress.Column(4)

End Sub
----------------------------------------
Sub PreviewHVL_Click()
On Error GoTo Err_PreviewHVL_Click

Dim stDocName As String

If IsNull([FullName]) Or IsNull([Address1]) Then
MsgBox "You must enter a Name and Address."
DoCmd.GoToControl "FindAddress"
GoTo Exit_PreviewHVL_Click
End If

stDocName = "Request for Visit Cancellation"
DoCmd.OpenReport stDocName, acPreview

Exit_PreviewHVL_Click:
Exit Sub

Err_PreviewHVL_Click:
MsgBox Err.Description
Resume Exit_PreviewHVL_Click

End Sub
----------------------------------------
Sub CloseForm_Click()
'** Close the form
On Error GoTo Err_CloseForm_Click

DoCmd.Close
DoCmd.Restore

Exit_CloseForm_Click:
Exit Sub

Err_CloseForm_Click:
MsgBox Err.Description
Resume Exit_CloseForm_Click

End Sub

================================================================
On the report's property sheet, the only calls are
On Open
=[DoCmd].[maximize]
On Close
=[DoCmd].[restore]
On No Data
Event Procedure
(as shown previously)

Dirk Goldgar said:
M Skabialka said:
I added the following code to the report:
Private Sub Report_Close()
Me.Visible = True
End Sub

Now I can close the report from the close button or the X in the
corner and the form stays open, but as soon as I open the report in
design mode, the form disappears or closes. All of the code on the
report validates entries on the form; or closes it when the close
button is selected. Nothing else tells it to become invisible or
close.

1) I have never used macros and there aren't any in this or any
database I have created.

2) There are no calls to any functions in this report's code. Here's
the entire report code module:
Option Compare Database
Option Explicit
Private Sub Report_NoData(Cancel As Integer)
MsgBox "There is no data for this report. Cancelling report..."
Cancel = -1
End Sub
Private Sub Report_Close()
Me.Visible = True
[DoCmd].[Restore]
End Sub

Any other ideas about why my form closes when I go into design mode
on the report?

Thanks,
Mich

This is getting odder and odder. In the first place, this code you
added ...
Private Sub Report_Close()
Me.Visible = True
End Sub

... should have no effect whatever on the form. In the report's code
module, the "Me" keyword refers to the report, not the form. So I can't
understand why that code would make any difference to what's going on.
Yet you say it does. Very odd.
2) There are no calls to any functions in this report's code. Here's

That's not what I was referring to when I suggested "a call to a public
function (e.g, "=CloseForm('frmRptParms')") executed from one of the
report's events." This sort of call isn't made from the report's code
module, but from the properties of the report itself. If this
techniques is being used, then if you open the report's property sheet
in design view and look on the Event tab, on one of the event property
lines you'll see a function expression similar to the example I gave --
an equals sign followed by a function name, possibly with arguments
specified inside the parentheses. But if you look at the event
properties and see nothing but "[Event Procedure" (on the On Close and
On No Data lines), this isn't what's going on.

If there's nothing on the report, the only other thing I can think of is
something on the form, but it sure didn't sound like it. Would you care
to post the contents of the form's code module, too?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
M Skabialka said:
It's long - but here it is:

=======================================================
Option Compare Database
Option Explicit

Private Sub Combo61_AfterUpdate()
'** Place employee data from combo into fields as shown
Dim f As Form
Set f = Forms![Request for Visit Cancellation]
f![FullName] = f!Combo61.Column(2) + " " + f!Combo61.Column(1)
f![Social Security #] = f!Combo61.Column(4)
f![BirthDate] = f!Combo61.Column(6)
f![Birth City] = f!Combo61.Column(8)
f![Birth StateOrProvince] = f!Combo61.Column(9)
f![Birth PostalCode] = f!Combo61.Column(10)
f![Birth Country] = f!Combo61.Column(11)

End Sub
----------------------------------------
Private Sub FindAddress_AfterUpdate()
'**Place predefined address into fields as shown
Forms![Request for Visit Cancellation]![Address1] =
Forms![Request for Visit Cancellation]!FindAddress.Column(1)
Forms![Request for Visit Cancellation]![Address2] =
Forms![Request for Visit Cancellation]!FindAddress.Column(2)
Forms![Request for Visit Cancellation]![Address3] =
Forms![Request for Visit Cancellation]!FindAddress.Column(3)
Forms![Request for Visit Cancellation]![Address4] =
Forms![Request for Visit Cancellation]!FindAddress.Column(4)

End Sub
----------------------------------------
Sub PreviewHVL_Click()
On Error GoTo Err_PreviewHVL_Click

Dim stDocName As String

If IsNull([FullName]) Or IsNull([Address1]) Then
MsgBox "You must enter a Name and Address."
DoCmd.GoToControl "FindAddress"
GoTo Exit_PreviewHVL_Click
End If

stDocName = "Request for Visit Cancellation"
DoCmd.OpenReport stDocName, acPreview

Exit_PreviewHVL_Click:
Exit Sub

Err_PreviewHVL_Click:
MsgBox Err.Description
Resume Exit_PreviewHVL_Click

End Sub
----------------------------------------
Sub CloseForm_Click()
'** Close the form
On Error GoTo Err_CloseForm_Click

DoCmd.Close
DoCmd.Restore

Exit_CloseForm_Click:
Exit Sub

Err_CloseForm_Click:
MsgBox Err.Description
Resume Exit_CloseForm_Click

End Sub

================================================================
On the report's property sheet, the only calls are
On Open
=[DoCmd].[maximize]
On Close
=[DoCmd].[restore]
On No Data
Event Procedure
(as shown previously)

I don't really see anything there that is obviously the cause of the
problem. Your use of "=[DoCmd].[maximize]" and "=[DoCmd].[restore]" as
event properties is not something I've seen before, but I just made a
quick test and it seemed to work without problems. (I might point out
that, since the report's OnClose property is not set to "[Event
Procedure]", your Report_Close event procedure is not being executed at
all.) Just for laughs, you might try removing the "=[DoCmd].[maximize]"
and "=[DoCmd].[restore]" values from the OnOpen and OnClose event
properties, and see if the problem goes away.


If the problem doesn't go away, I wonder if you'd mind sending me a
cut-down copy of your database, containing only the elements necessary
to demonstrate the problem, compacted and then zipped to less than 1MB
in size (preferably much smaller). I'll have a look at it, time
permitting. You can send it to the address derived by removing NO SPAM
from the reply address of this message.

Side note: is the form in question the same "Request for Visit
Cancellation" form that is referred to explicitly in the code you
posted? That is, is this the code from that form's module? If so, you
could make that code a lot more efficient by substituting the "Me"
keyword for the reference "Forms![Request for Visit Cancellation]" every
where you have it in there.
 
Back
Top