If IsLoaded to detect from multiple forms

  • Thread starter Hugh self taught
  • Start date
H

Hugh self taught

Hi,

I open another form from the one I'm working on (dbl click event) to be able
to add / edit data during data capture. When I close that form I requery the
original form where I originated the "openform" from. That works fine,
however I now need to open that form from more than one form but the "If -
IsLoaded" statement tells me it needs to be the first line in the statement
if I use it as "Else If"

Here is the current code when opening from the form:

If CurrentProject.AllForms("frmCouplesNumberAssign").IsLoaded Then
Forms!frmCouplesNumberAssign.Requery
DoCmd.Close acForm, "frmStudios", acSaveYes

Else: DoCmd.Close
DoCmd.OpenForm ("Main Menu")

End If

I somehow need to check for the following & requery that originating form

If CurrentProject.AllForms("frmCouplesLookup").IsLoaded Then
 
M

Mr. B

Hugh self taught,

Here is the code that will produce message boxes for multiple forms that
could be open. This code only returns the message for the first form that it
finds open.

If CurrentProject.AllForms("Form7").IsLoaded Then
MsgBox "Form 7 is loaded!"
ElseIf CurrentProject.AllForms("Form6").IsLoaded Then
MsgBox "Form 6 is loaded!"
ElseIf CurrentProject.AllForms("Form5").IsLoaded Then
MsgBox "Form 5 is loaded!"
Else
MsgBox "Neither form is loaded"
End If

You will need to change the form names to your form names.
 
G

Graham Mandeno

Hi Hugh

Do you want the user to be able to do anything else during the time the
add/edit form is open? If not, then open it in dialog mode. The code that
opens the form will then be suspended until that form is closes (or makes
itself invisible) and then the calling form can requery itself:

DoCmd.OpenForm <you form name>, WindowMode:=acDialog
Me.Requery

If that's not feasible then the calling form could pass its own name via the
OpenArgs property:

DoCmd.OpenForm <you form name>, OpenArgs:=Me.Name

Then the called form knows which form to requery:

If IsNull(Me.OpenArgs) then
DoCmd.OpenForm "Main Menu"
Else
If CurrentProject.AllForms( Me.OpenArgs ).IsLoaded Then
Forms( Me.OpenArgs ).Requery
End If
End If
DoCmd.Close acForm, Me.Name

Notice a couple of points here:

1. Always specify the name and type of the object for DoCmd.Close, otherwise
you will one day run into a hard-to-track bug where the wrong object is
being closed because of a timing issue.
DoCmd.Close is ambiguous
DoCmd.Close acForm, Me.Name is not

2. Using acSaveYes on a DoCmd.Close saves the *design changes*, not the
data. Is that really what you want to do? The data will be saved
automatically.
 
H

Hugh self taught

Thanks Mr B.

I must have messed up my syntax when I tried it originally because this time
round it works perfectly.
 
H

Hugh self taught

Thanks Graham,

I've made note of your options for achieving my objective & will try them
with other activities I am planning.

I made note of your points of note ie: DoCmd.Close without parameters. When
I started have different forms to close it became very apparent as the wrong
form closed. In this instance there is only one form open but I've added the
parameters as suggested.

Graham Mandeno said:
Hi Hugh

Do you want the user to be able to do anything else during the time the
add/edit form is open? If not, then open it in dialog mode. The code that
opens the form will then be suspended until that form is closes (or makes
itself invisible) and then the calling form can requery itself:

DoCmd.OpenForm <you form name>, WindowMode:=acDialog
Me.Requery

If that's not feasible then the calling form could pass its own name via the
OpenArgs property:

DoCmd.OpenForm <you form name>, OpenArgs:=Me.Name

Then the called form knows which form to requery:

If IsNull(Me.OpenArgs) then
DoCmd.OpenForm "Main Menu"
Else
If CurrentProject.AllForms( Me.OpenArgs ).IsLoaded Then
Forms( Me.OpenArgs ).Requery
End If
End If
DoCmd.Close acForm, Me.Name

Notice a couple of points here:

1. Always specify the name and type of the object for DoCmd.Close, otherwise
you will one day run into a hard-to-track bug where the wrong object is
being closed because of a timing issue.
DoCmd.Close is ambiguous
DoCmd.Close acForm, Me.Name is not

2. Using acSaveYes on a DoCmd.Close saves the *design changes*, not the
data. Is that really what you want to do? The data will be saved
automatically.
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand



Hugh self taught said:
Hi,

I open another form from the one I'm working on (dbl click event) to be
able
to add / edit data during data capture. When I close that form I requery
the
original form where I originated the "openform" from. That works fine,
however I now need to open that form from more than one form but the "If -
IsLoaded" statement tells me it needs to be the first line in the
statement
if I use it as "Else If"

Here is the current code when opening from the form:

If CurrentProject.AllForms("frmCouplesNumberAssign").IsLoaded Then
Forms!frmCouplesNumberAssign.Requery
DoCmd.Close acForm, "frmStudios", acSaveYes

Else: DoCmd.Close
DoCmd.OpenForm ("Main Menu")

End If

I somehow need to check for the following & requery that originating form

If CurrentProject.AllForms("frmCouplesLookup").IsLoaded Then
 

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