check form open and bring it to front

I

iccsi

I would like to check form open or not, if not then open the form and
bring it to front, if it opens then bring it to front.

I tried to look myform.open, but does not exist.
I just wonder any command to do the task.

Your help is great appreciated,
 
A

Access Developer

DoCmd.OpenForm does exactly what you ask... look it up in Help. You can
defeat it, if you try, by opening other forms as Modal, or as Popup, or as
Dialog... but with all forms opened "acNormal", it opens the form if not
already open, and sets Focus to it (which brings it to the front); if open,
it just sets Focus (which brings it to the front).

Larry Linson
Microsoft Office Access MVP
 
M

Marshall Barton

iccsi said:
I would like to check form open or not, if not then open the form and
bring it to front, if it opens then bring it to front.

I tried to look myform.open, but does not exist.
I just wonder any command to do the task.

I think this kind of thing should do that:

If CurrentProject.AllForms![form name].IsLoaded Then
DoCmdSelectObject acForm, "form name"
Else
DoCmdOpenForm "form name"
End If

Be sure to check VBA Help for all the stuff that you are not
already familiar with.
 
D

David-W-Fenton

DoCmd.OpenForm does exactly what you ask... look it up in Help.
You can defeat it, if you try, by opening other forms as Modal, or
as Popup, or as Dialog... but with all forms opened "acNormal", it
opens the form if not already open, and sets Focus to it (which
brings it to the front); if open, it just sets Focus (which brings
it to the front).

Let me second what Larry said -- DoCmd.OpenForm will open it if it's
not open, or bring it to the front if it is (unless, as Larry says,
you've set the properties of the form such that it can't).
 
D

David-W-Fenton

iccsi said:
I would like to check form open or not, if not then open the form
and bring it to front, if it opens then bring it to front.

I tried to look myform.open, but does not exist.
I just wonder any command to do the task.

I think this kind of thing should do that:

If CurrentProject.AllForms![form name].IsLoaded Then
DoCmd.SelectObject acForm, "form name"
Else
DoCmd.OpenForm "form name"
End If

Be sure to check VBA Help for all the stuff that you are not
already familiar with.

Why would you bother to check, given that DoCmd.OpenForm does the
job without any conditional checking?

(also, note that you left out the period between DoCmd and the
command in your sample code -- I've restored it in the quoted code).
 
M

Marshall Barton

David-W-Fenton said:
Marshall Barton said:
iccsi said:
I would like to check form open or not, if not then open the form
and bring it to front, if it opens then bring it to front.

I tried to look myform.open, but does not exist.
I just wonder any command to do the task.

I think this kind of thing should do that:

If CurrentProject.AllForms![form name].IsLoaded Then
DoCmd.SelectObject acForm, "form name"
Else
DoCmd.OpenForm "form name"
End If

Be sure to check VBA Help for all the stuff that you are not
already familiar with.

Why would you bother to check, given that DoCmd.OpenForm does the
job without any conditional checking?

(also, note that you left out the period between DoCmd and the
command in your sample code -- I've restored it in the quoted code).


Good points and I woke up as soon as I saw Larry's reply.
Too bad that once sent, there is no way to delete a post.
 

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