What code to use when testing if a form is loaded?

  • Thread starter Thread starter Jrb via AccessMonster.com
  • Start date Start date
J

Jrb via AccessMonster.com

Hello to everyone,

Can anyone help me how could I make a VB code to test if a form has been
loaded or currently been loaded in ACCESS 2003? I have used a built-in
function in ACCESS 97 such as:

If Isloaded("FormName") then --- to test whether the form is currently
loaded
....
End If

It works, but when I tried to use in ACCESS 2003, it seems it was removed,
modified or deleted from the built-in functions? I can't find such a function.


Your help is very much appreciated. Thanks in advance...


Jrb
 
Hello to everyone,

Can anyone help me how could I make a VB code to test if a form has been
loaded or currently been loaded in ACCESS 2003? I have used a built-in
function in ACCESS 97 such as:

If Isloaded("FormName") then --- to test whether the form is currently
loaded
....
End If

It works, but when I tried to use in ACCESS 2003, it seems it was removed,
modified or deleted from the built-in functions? I can't find such a function.

Your help is very much appreciated. Thanks in advance...

Jrb

The IsLoaded function in Access 97 is a User Defined function, copied
from the Utility module in the Northwind sample database.

In Access 2003 it is a built-in function, referenced differently.
Here is all the information on both.

What version of Access?
Access 2002 or newer:
If Not CurrentProject.AllForms("FormA").IsLoaded Then
Do something here
Else
Do something else
End If

In Access 97, copy this function (from the Northwind.mdb sample
database) to a module.

Function IsLoaded(ByVal strFormName As String) As Integer
' Returns True if the specified form is open in Form view or
Datasheet
view.

Const conObjStateClosed = 0
Const conDesignView = 0

If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <>
conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If
End Function

Then code:
If Not IsLoaded("FormA") Then
Do this
Else
Do that
End if
 
Have you tried something like:

Dim openFormTest As Boolean
openFormTest = CurrentProject.AllForms("frmMessageCenter").IsLoaded
MsgBox openFormTest

I know that the function works as I tested it in both 2002 and 2003.

Lance
 
Hello fredg,

Thanks a lot for your great advice and the code as well. It works very well.

Here's another new question related to this. I'm adding a new record to my
Form/Subform and my subform contained dropdown list. This comboBox list
doesn't contain a data since it is new so I code in "Not In List" procedure
that if the data is not found, then pop-up the master file form data entry.
After adding the new record, I want to reflect it to the comboBox field, so I
used your code to test whether the form has been loaded, and then requeried.
I tried something like this:

If CurrentProject.AllForms("FormA").IsLoaded Then
!Forms!Mainform!SubForm.Form.ComboBox.Requery
end if

I gives me an error, "You must save first the field before you can requery".
I remember before I used the same technique in ACCESS 97 and it works. Maybe
I missed something or I was wrong? I lost my source code in ACCESS 97 that's
why I started all over from scratch.

Can you help me with this. Thanks for you time and advice. I really
appreciate it..

Jrb said:
Hello to everyone,
[quoted text clipped - 13 lines]

The IsLoaded function in Access 97 is a User Defined function, copied
from the Utility module in the Northwind sample database.

In Access 2003 it is a built-in function, referenced differently.
Here is all the information on both.

What version of Access?
Access 2002 or newer:
If Not CurrentProject.AllForms("FormA").IsLoaded Then
Do something here
Else
Do something else
End If

In Access 97, copy this function (from the Northwind.mdb sample
database) to a module.

Function IsLoaded(ByVal strFormName As String) As Integer
' Returns True if the specified form is open in Form view or
Datasheet
view.

Const conObjStateClosed = 0
Const conDesignView = 0

If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <>
conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If
End Function

Then code:
If Not IsLoaded("FormA") Then
Do this
Else
Do that
End if
 
Hi LTofsrud,

You are really a great help. Thank you very much for your code. It works the
same above. I really appreciate your help. I hope you could give more help in
my coming queries.

God Bless!!!

Jrb
Have you tried something like:

Dim openFormTest As Boolean
openFormTest = CurrentProject.AllForms("frmMessageCenter").IsLoaded
MsgBox openFormTest

I know that the function works as I tested it in both 2002 and 2003.

Lance
Hello to everyone,
[quoted text clipped - 13 lines]
 
Hello fredg,

Thanks a lot for your great advice and the code as well. It works very well.

Here's another new question related to this. I'm adding a new record to my
Form/Subform and my subform contained dropdown list. This comboBox list
doesn't contain a data since it is new so I code in "Not In List" procedure
that if the data is not found, then pop-up the master file form data entry.
After adding the new record, I want to reflect it to the comboBox field, so I
used your code to test whether the form has been loaded, and then requeried.
I tried something like this:

If CurrentProject.AllForms("FormA").IsLoaded Then
!Forms!Mainform!SubForm.Form.ComboBox.Requery
end if

I gives me an error, "You must save first the field before you can requery".
I remember before I used the same technique in ACCESS 97 and it works. Maybe
I missed something or I was wrong? I lost my source code in ACCESS 97 that's
why I started all over from scratch.

Can you help me with this. Thanks for you time and advice. I really
appreciate it..

Jrb said:
Hello to everyone,
[quoted text clipped - 13 lines]

The IsLoaded function in Access 97 is a User Defined function, copied
from the Utility module in the Northwind sample database.

In Access 2003 it is a built-in function, referenced differently.
Here is all the information on both.

What version of Access?
Access 2002 or newer:
If Not CurrentProject.AllForms("FormA").IsLoaded Then
Do something here
Else
Do something else
End If

In Access 97, copy this function (from the Northwind.mdb sample
database) to a module.

Function IsLoaded(ByVal strFormName As String) As Integer
' Returns True if the specified form is open in Form view or
Datasheet
view.

Const conObjStateClosed = 0
Const conDesignView = 0

If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <>
conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If
End Function

Then code:
If Not IsLoaded("FormA") Then
Do this
Else
Do that
End if

Did you change "FormA" to the actual name of your form?
Did you requery the combo box itself ... Me!ComboName.Requery?

Other than that, without seeing your NotInList code, I can't help you.
This is actually a different thread. If you still need help, please
start a new thread
 
Hi fredg,

Thank you for your time answering my queries. I changed the "Form A" to the
name of the Mainform. The problem lies when I tried to enter a new record
that was not in the list of the combo box. So, I have to pop-up the form for
master file where I can do the data entry to add new record. After adding
the new record and tried to requery the:

Forms!Mainform!Subform.ComboBox.Requery - it gives me that error. I solved it
by Undoing the value of the combo box bofore the pop-up master file form
loaded. Then the command works very well. The new value now is on the list.

What I want to figure out is, I want the value of the Mainform combo box to
be passed to the pop-up master file form so the user not need to re-enter
what he entered in the Mainform. Then when saving the record, to pass again
back to the Mainform combo box the value of the newly added record so the
user not need to re-type the value to the combo box.

Is it possible? Thanks again for your time responding to my query.

Jrb
Hello fredg,
[quoted text clipped - 66 lines]
Did you change "FormA" to the actual name of your form?
Did you requery the combo box itself ... Me!ComboName.Requery?

Other than that, without seeing your NotInList code, I can't help you.
This is actually a different thread. If you still need help, please
start a new thread
 
Back
Top