Close form by code that is in AcDialog Window mode? (1 Viewer)

moori

Registered User.
Local time
Today, 16:53
Joined
Feb 8, 2012
Messages
31
Hello everyone,

is there a possibility to close a form that is in dialog box style by code?

Code:
DoCmd.Close acForm, "frmQuery"
does not work. I am afraid that I can´t do anything by code until the user closes the form, right? Is there no way around, maybe by addressing the vbFormControlMenu?

I have a query´s result displayed in a form. If the query is empty, I want the form to be closed and a message to be shown.
When my query output form is in AcWindowNormal mode, it works. But then my other open forms are restored down and I want them to stay maximized, that´s why I chose the dialog box.

Here is my code:

Code:
DoCmd.OpenForm "frmQuery", acNormal, , , acFormPropertySettings, acDialog

' If Query is empty, close Query Window and show Dialog Box with Message
If DCount("*", "Query") = 0 Then
            ' HERE SOMEHOW CLOSE FORM "frmQuery"
            MsgBox "Query empty!" 
            Exit Sub
        End If
Does anyone have an idea?
I would also be happy to make my form normal window style, if there is a possibility to leave the other forms maximized on closing it.

Regards,
moori
 

Fuse3k

Registered User.
Local time
Today, 17:53
Joined
Oct 24, 2007
Messages
74
Why not rearrange your code? Check for records first then open the form?

Code:
' If Query is [B]NOT[/B] empty, [B]OPEN [/B]Query Window 
If [B]Not [/B]DCount("*", "Query") = 0 Then
     DoCmd.OpenForm "frmQuery", acNormal, , , acFormPropertySettings, acDialog
Else
     MsgBox "Query empty!" 
     Exit Sub
      
 End If
 

SforSoftware

(NL) SnelStart specialist
Local time
Today, 23:53
Joined
Aug 16, 2003
Messages
239
I would also be happy to make my form normal window style, if there is a possibility to leave the other forms maximized on closing it.

Set in the Form's properties Modal=True and Popup=True, and you should be able to open it in Normal mode.
 

moori

Registered User.
Local time
Today, 16:53
Joined
Feb 8, 2012
Messages
31
Thanks Fuse3k, that was it!
I didn´t know you can check the query without opening it, haha - duh! :D

Bert, your approach did not work, I could still not close the form.

Thanks for your answers!!
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:53
Joined
Feb 19, 2002
Messages
43,484
When formA opens a modal formB, code execution in formA is suspended until formB closes so no code in formA could close formB. You would need a Timer event or something in formB to prompt the user to close the form after some period. Or the Timer event in formB could just close the form but that would be rude:)
 

smig

Registered User.
Local time
Tomorrow, 00:53
Joined
Nov 25, 2009
Messages
2,209
another option is to open the form as non dialog and run the code. after the code finished "reopen" as dialog.
as it's already open it won't close and reopen. it will only chnage it's state into dialog.
 

moori

Registered User.
Local time
Today, 16:53
Joined
Feb 8, 2012
Messages
31
Oh no, I really would not want to appear rude, Pat ;-)
Smig, this will also restore down my other open forms.
I´ll stick to Fuse3k´s nice and easy solution!
Gracias!
 

Users who are viewing this thread

Top Bottom