Share via

Call dialog form

Anonymous
2017-01-07T20:32:53+00:00

A little question about dialog forms.

I create a form (1 in the image), modal and dialog. If I call my form from VBA (from form 2) with

DoCmd.OpenForm "frmMyFormCalled", acNormal, , , acFormAdd , acDialog

I have the title (3 in the image), that I don't want. If I don't use the acDialog parameter, the form not have the title, is dialog, but my code continue until exit routine (and I want stop my code until I close the called form).

Why?

Thanks for the help.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2017-01-09T23:28:35+00:00

A few things.

I assume your application is not using overlapping windows. Thus as a “normal” course of action when you open a new form, it hides all previous forms below.

However, two types of forms will appear “on top” as separate windows.

They are:

   Dialog forms   (appears as separate window on top)

   Popup forms    (appears as separate window on top)

Note that modal forms DO NOT appear as separate windows (if your application setting is tabs as opposed to separate windows).

So don’t confuse modal forms with dialog forms or popup forms (they are all VERY different). So 3 VERY different kinds of forms here and they all behave VERY differently.

Also:

Modal forms - they do not halt VBA code that opened the form

Popup forms – they do not halt VBA code that opened the form.

Dialog forms – they WILL HALT the VBA code that opened the form.

Regular forms – they do not halt VBA code that opened the form.

The problem here is you are wanting dialog like behaviour in regards to the calling code halting but you don’t want nor need a dialog form.

About the best way to achieve the above is to modify your calling code to NOT wait, but simply have the form you opened run some code when you hit the close button (or place code in the close event of that second form.

Form1 code we have:

Option Compare Database

Option Explicit

Private Sub Command0_Click()

DoCmd.OpenForm "formB"

End Sub

Public Function OkContinue()

' code here runs AFTER form B is closed

MsgBox "code runs here after form B closed"

End Function

Note how we have a SECOND routine of code that will run when the user closes formB. So we not really waiting in the same VBA routine, but we have code run when the user hits “ok” or “save” or whatever the user supposed to do in the second form.

The code in the second form thus looks like:

Option Compare Database

Option Explicit

Dim frmPrevious      As Form

Private Sub Form_Open(Cancel As Integer)

Set frmPrevious = Screen.ActiveForm

End Sub

Private Sub Form_Close()

frmPrevious.OkContinue

End Sub

The code is written the above way since that second form is OFTEN being called from several forms and that is no doubt WHY you wanted code to halt. And even if your goal is NOT the ability for several different forms to call that dialog “like” form, the above shows how you can do this without hardcoding the form name in the second form B.

So you adopt a coding standard that says:

For any form that calls our cool new form "B" the VBA code will NOT wait, but assumes that a public function called OkContinue() will exist in the calling form. The result is thus any form can call that form, and while the VBA code will NOT wait you WILL have some code run AFTER the user is done and closes that form.

Regardless if you needing to re-use that form, or simply wanting the code to “wait”, the above code snip simply in place of having code wait simply means that some code runs AFTER the users closes the form, but your VBA code is not waiting. And we don't hard code the form code that form B calls with the above approach.

You STILL want to set that second form as modal (you find that in the “other” tab of the property sheet – but a modal form is NOT the same as dialog form.

The “main” difference is with a modal form you can use the ribbon, and focus CAN change to a popup form.

However with a dialog form, you can’t use the ribbon, you can’t change focus to popup forms, and the VBA code does halt – you can quite much think of a dialog form like the msgbox command – VBA and focus is frozen to that one object. Such limitations don't exist with a modal form.

Modal forms however do NOT permit focus to change to previous forms or any other form with the exception of a popup form. So modal forms are common since they force the user to un-cork or traverse the previous set of forms they used to reach that point in the application - so modal forms are common for controlling how the user going to navigate your application, but they are VERY different then dialog forms.

Regards,

Albert D. Kallal (Access MVP)

Edmonton, Alberta Canada

Was this answer helpful?

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2017-01-09T23:42:17+00:00

    THANK YOU Albert.

    Was this answer helpful?

    0 comments No comments
  2. Tom van Stiphout 40,211 Reputation points MVP Volunteer Moderator
    2017-01-07T23:13:17+00:00

    That's a Windows thing and it's by design. If I had to guess it is so you can move the dialog, and to allocate space for the system menu and buttons.

    Was this answer helpful?

    0 comments No comments