a Form was opened as modal Dialog?

N

Nhan

Hi,
Which property tell me that a form is opened as modal dialog with
docmd.openform ...., acDialog?

I have checked the property Modal and Popup, these are false.

Thanks
Nhan
 
A

Albert D. Kallal

Well, acDialog and model are very different.

You can read about this here:

http://www.members.shaw.ca/AlbertKallal/Dialog/Index.html
Which property tell me that a form is opened as modal dialog with
docmd.openform ...., acDialog?

If you use the acDialog...then the code that follows the above line will NOT
run.

You can certainly pass a argument to the form, and "tell" it you are
acDialog

docmd.OpenForm "formname",acNormal,,,,acDialog,"dialog"

Then, in the forms on-load event, you could check:

if me.OpenArgs = "dialog" then
this is a dialog form....

-
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
(e-mail address removed)
http://www.members.shaw.ca/AlbertKallal
 
N

Nhan

But you don't tell me,
Which property tell me that a form is opened as modal dialog with
docmd.openform ...., acDialog?

Here I mean "dialog". The form is loaded, in code of this form (for instance
when user clicks button) I want to know, as fi this form is opened as dialog
or normal. How can I do it?
 
D

Dirk Goldgar

Nhan said:
But you don't tell me,
Which property tell me that a form is opened as modal dialog with
docmd.openform ...., acDialog?

Here I mean "dialog". The form is loaded, in code of this form (for
instance when user clicks button) I want to know, as fi this form is
opened as dialog or normal. How can I do it?

As far as I know, there is no property that will tell you that.
However, if the form is not normally a popup form, then I *think* you
can distinguish the difference between opening it normally and opening
it in dialog mode by whether or not its parent window is the Access
application window.

Just experimentally, I tried this code:

'----- declaration of API function at module level -----
' API function to return the handle of the parent window of the
' specified window.
Private Declare Function apiGetParent _
Lib "User32" Alias "GetParent"
(ByVal hWnd As Long) As Long
'----- end declaration of API function -----

And then in a form event:

'----- start of code -----
Dim lngParentHWnd As Long

lngParentHWnd = apiGetParent(Me.hWnd)

If lngParentHWnd = hWndAccessApp Then
MsgBox "This form is opened in dialog mode!"
Else
MsgBox "This form is not opened in dialog mode."
End If
'----- end of code -----

However, I found that if the form's PopUp property is set to True, then
this code thinks the form is open in dialog mode. If your form is not
normally a popup form, though, maybe this will work for your purposes.
Please be aware that I haven't tested this much at all, so I make no
promises about it.
 
N

Nhan

Thanks,
I need a universal solution. My form is not a popup form, is a normal
Dataform, but sometime is showed as dialog, sometime as modal. Because the
position of dialog windows is not similar to the normal, and my program need
to do something in this case...
 
R

Rob Oldfield

Albert's solution _is_ universal. It's just a slight kludge, and involves
typing a few extra commas and a piece of text.

(i.e. if Albert and Dirk haven't come up with anything better, then there
probably isn't anything better.)
 
A

Albert D. Kallal

Nhan said:
Thanks,
I need a universal solution. My form is not a popup form, is a normal
Dataform, but sometime is showed as dialog

If you are talking about an actual dialog form, then the ONLY way to open a
form in dialog mode is to use code.

Since you HAVE TO use code to open a form in dialog mode, then why not use
my suggestion to pass this fact via open args?

Further, if open arges is already being used, then you can either:

a) use the split command to parse out multiple args for the OpenArgs

or

b) simply make a public property of the form that gets set when the form is
NOT dialog. (however, this would add an extra line of code when you open a
form in non dialog mode, and you would have to remember to do this, and also
possibly modify existing code. So, best bets are to using openArgs...

Any particular reason why you don't use openargs in the acDialog case?
 
N

Nhan

Thanks for your help
If you are talking about an actual dialog form, then the ONLY way to open a
form in dialog mode is to use code.

Since you HAVE TO use code to open a form in dialog mode, then why not use
my suggestion to pass this fact via open args?

when we HAVE TO pass a parameter in openargs, then that is not an universal
solution. When a Form is opened as dialog (acDialog), and OpenArgs = null
(the programer forgot to pass parameter to OpenArgs).

I have found a solution. I use API function: IsWindowEnabled to check, if
the access main window is currently enabled. When YES, the form is normal
opened, when NO, the form is opened as dialog. I have tested. When you find
anything not right, please tell me.

Thanks
Nhan
 
A

Albert D. Kallal

when we HAVE TO pass a parameter in openargs, then that is not an
universal
solution.

Well, my point here is that model forms can be opened by wizards, by the
simple fact of creating a custom menu bar, and many many other ways.

If your question was to find out if a form is model, then I would accept the
need for a solution that tells you this fact, since NO code is needed to
open a form in model.

However, with acDialog, since CODE MUST be used, then it seems to me the
simple solution to add something the open args, and be done with this
problem.

I just don't understand your huge effort in trying to find a universal
solution, but then you come back and state the problem is that you as a
developer is just too lazy to modify the calling code? This does not make a
lot of sense!! You are willing to make such huge and un-necessary effort to
figure out if a you as a developer was too lazy to pass a value in the open
args?

You are wasting valuing time for no perceived benefit.

What are you going to do in the case that the developer forgets to include
the acDialog in the calling code? How will you know that the developer
actually wanted the form to be acDioalog, or in fact it was a mistake?

My suggestion was based on the fact that it takes a GOOD BIT of effort to
open a form in acDialog, and if the application needs special handling in
this case, then I can't imagine the effort to include a parameters via
openargs would not be a solution here?
When you find anything not right, please tell me.

Yes, my point is the cost of your solution is more then the time and
resources spent to obtain the solution. Further, what happens if the
developer forgets to include the acDialog parameter? You main point to me
what that the developer might forget to include the OpenArgs parms, and I am
throwing this right back at you, and stating that the developer might forget
to include the acDialog parm.

This whole thing revolves around the fact that it takes a conscious effort
to open a form in acDialog. If it did not take any effort on the developers
side, then I am 100% in agreement with you on the need for a universal
solution.

So, my point here is that your solution gains little, or nothing in terms of
saved time and effort.

The fact is you can always do a global search on code for the acDialog
parameter, and in a number of minutes find ALL occurrences of this. (but, if
the developer forgets to include the acDialog..then you got the same problem
as when you use openargs).

Perhaps you are willing to re-fund the wasted time to your employer or
client who is paying for this?
 
N

Nhan

I'm sory. I think, you don't understand me.
Your suggestion is a solution. But I waited for another solution, I knew
your solution, :)
What are you going to do in the case that the developer forgets to include
the acDialog in the calling code? How will you know that the developer
actually wanted the form to be acDioalog, or in fact it was a mistake?

The developers forgets to pass a parameter in OpenArgs arguments, to mark,
that the form is acDialog. (Perhaps I wrote false, I can't perfekt english.)
I, self, know this situation. The compiler can't tell us, that we forget..,
and we are no machine, any computers, we make error.
When developers forgets pass acDialog argument, then the form is not opened
as dialog, then I don't want that my or any function "regconize", that it is
a dialog.

Thanks
Nhan
 
A

Albert D. Kallal

I do understand your point. And, to fair, at the end of the day, it is
BETTER to find a Universal solution as your desire!!

So, don't let me deter you from finding a solution (and, seems like you
did!!).

Further, there is ONE BIG point in your favor for the kind of solution:

Moving code into a EXISTING application. You see, if you write the code to
"know" when the form is acDialog, and you can incorporate this code into
EXISTING applications without having to go and modify the OpenForms commands
all over the place (on the other hand, one of my applications with 160 forms
has maybe, 2, or 3 acDialog forms...and they would be VERY easy to find!!).

However, at the end of the day, I do accept, and understand your desire for
a solution..and good developers never stop looking for the best solution!!

It seems your persistence has paid off, and you did eventually find a
solution!
 

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