Form IsLoaded (1 Viewer)

Gismo

Registered User.
Local time
Tomorrow, 00:32
Joined
Jun 12, 2017
Messages
1,298
Hi all,

On close current form, I an trying to do and action if another form is open
It is not doing anything with below code

If CurrentProject.AllForms(PurchaseOrder_Requisition).IsLoaded = True Then
...
End If

and when I use the below code, I get a type mismatch error

If CurrentProject.AllForms("PurchaseOrder_Requisition").IsLoaded = True Then
...
End If

Please could you assist
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:32
Joined
Feb 28, 2001
Messages
27,188
First, as a really simple test, drop the "= True" behind the .IsLoaded, since that property will itself either be true or false. I believe you can also drop the "CurrentProject." since that is the default place to look for the AllForms collection. Finally, it MIGHT be that you need to use the formal name of that form if you are going through "AllForms" - so ask for AllForms("Form_PurchaseOrder_Requisition") - just for snorts & giggles.
 

Gismo

Registered User.
Local time
Tomorrow, 00:32
Joined
Jun 12, 2017
Messages
1,298
First, as a really simple test, drop the "= True" behind the .IsLoaded, since that property will itself either be true or false. I believe you can also drop the "CurrentProject." since that is the default place to look for the AllForms collection. Finally, it MIGHT be that you need to use the formal name of that form if you are going through "AllForms" - so ask for AllForms("Form_PurchaseOrder_Requisition") - just for snorts & giggles.
I tried removing the =True before, did not make a difference
Using just AllForms("Form_PurchaseOrder_Requisition") gives a Sub or Function not defined error

Private Sub Close_Click()
On Error GoTo Close_Click_Err

DoCmd.Close , ""


If AllForms("Form_PurchaseOrder_Requisition").IsLoaded Then
DoCmd.Close "PurchaseOrder_Requisition"
End If


Close_Click_Exit:
Exit Sub

Close_Click_Err:
MsgBox Error$
Resume Close_Click_Exit

End Sub
 

Josef P.

Well-known member
Local time
Today, 23:32
Joined
Feb 2, 2023
Messages
826
The type mismatch error is here:
Code:
DoCmd.Close "PurchaseOrder_Requisition"
=>
Code:
If CurrentProject.AllForms("PurchaseOrder_Requisition").IsLoaded Then
    DoCmd.Close acForm, "PurchaseOrder_Requisition"
End If

This should also work without testing IsLoaded:
Code:
DoCmd.Close acForm, "PurchaseOrder_Requisition"
If the form is not open, it will not be closed. ;)

What is this?
Code:
DoCmd.Close , ""
To close the currently active object run:
Code:
DoCmd.Close
 

Users who are viewing this thread

Top Bottom