Prevent Form from Closing

E

el zorro

I have a form that allows the user to select the name of a person from a list
box, then click on a button to open a second form with the data for that
person. There is some VBA code for the On Close event of the second form that
updates the list on the first form.

However, if the user for some strange, unexplicable reason closes the first
form before closing the second form, Access generates an error message
saying, basically, "where the heck is the first form?" when the second form
is closed.

Isn't there a way to prevent the first form from being closed when the
second form is still open?

THanks!
 
S

Stefan Hoffmann

hi,

el said:
I have a form that allows the user to select the name of a person from a list
box, then click on a button to open a second form with the data for that
person. There is some VBA code for the On Close event of the second form that
updates the list on the first form.
There are three possible solutions:

1. Open the second form modal using the WindowMode:=acDialog parameter
of DoCmd.OpenForm.

2. Use for the first form

Private Sub Form_Close(Cancel As Integer)

Cancel = FormIsLoaded("Form2")

End Sub

Function FormIsLoaded(FormName As String) As Boolean
'by Douglas J Steele
On Error Resume Next

Dim strName As String

strName = Forms(FormName).Name
FormIsLoaded = (Err.Number = 0)

End Function

3. Use the FormIsLoaded() in Form2 before running your code.


mfG
--> stefan <--
 
E

el zorro

I tried #3, with Form IsLoaded(First_Form) as part of an If-Then statement,
but I couldn't get it to work. It didn't seem to recognize the function. Then
I realized that maybe I posted this in the wrong forum-- the user interface
is an .adp file connected to a SQL server. Will that function still work?
 
E

el zorro

Thank you! I manually set the Modal property to "Yes," and it works great!

AccessVandal via AccessMonster.com said:
And you don't to post that in multiple places. Here was my reply.

In the First form command button, open the second as a Dialog form..

DoCmd.OpenForm "yourformname", , , , , acDialog

This should prevent the user from closing the first form until the second
form is close.

Or you could just set the second form's properties manually on the property
sheet
Pop Up = Yes
Modal = Yes


el said:
I tried #3, with Form IsLoaded(First_Form) as part of an If-Then statement,
but I couldn't get it to work. It didn't seem to recognize the function. Then
I realized that maybe I posted this in the wrong forum-- the user interface
is an .adp file connected to a SQL server. Will that function still work?
[quoted text clipped - 30 lines]
mfG
--> stefan <--
 

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