Close form by code that is in AcDialog Window mode?

moori

Registered User.
Local time
Today, 04:01
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
 
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
 
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.
 
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!!
 
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:)
 
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.
 
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

Back
Top Bottom