Solved Returning from acDialog (1 Viewer)

ClaraBarton

Registered User.
Local time
Today, 03:28
Joined
Oct 14, 2019
Messages
463
I have Form A that calls Form B as a dialog so that when it returns it can run code determining ID, etc. On form B is a button that prints one label.
But because form B is made invisible for that one label, Form A thinks it's finished and pops up in front of the label. Is there no way of calling another form or report from a dialog form without returning to form A?

If form B was not dialog, it would not return to the original code and finish it. That code would then need to go in Load or Open which isn't always what is needed. How do you professionals do this?
 

moke123

AWF VIP
Local time
Today, 06:28
Joined
Jan 11, 2013
Messages
3,920
You lost me at form b is made invisible. Why?
What's the Label? A report?
What code needs to run? What ID, etc?
 

GPGeorge

Grover Park George
Local time
Today, 03:28
Joined
Nov 25, 2004
Messages
1,867
I have Form A that calls Form B as a dialog so that when it returns it can run code determining ID, etc. On form B is a button that prints one label.
But because form B is made invisible for that one label, Form A thinks it's finished and pops up in front of the label. Is there no way of calling another form or report from a dialog form without returning to form A?

If form B was not dialog, it would not return to the original code and finish it. That code would then need to go in Load or Open which isn't always what is needed. How do you professionals do this?
"...But because form B is made invisible for that one label, ..."

I am also puzzled. Why do you make form B invisible?
 

Mike Krailo

Well-known member
Local time
Today, 06:28
Joined
Mar 28, 2020
Messages
1,044
On form B is a button that prints one label.
Why not print your label from form A or from the code that happens after control passes back to form A? Form B is just a dialog form for gathering info from form B. So you should have all the data necessary to print your label or whatever it is your doing when you return back to form A.
 

LarryE

Active member
Local time
Today, 03:28
Joined
Aug 18, 2021
Messages
591
I have Form A that calls Form B as a dialog so that when it returns it can run code determining ID, etc. On form B is a button that prints one label.
But because form B is made invisible for that one label, Form A thinks it's finished and pops up in front of the label. Is there no way of calling another form or report from a dialog form without returning to form A?

If form B was not dialog, it would not return to the original code and finish it. That code would then need to go in Load or Open which isn't always what is needed. How do you professionals do this?
You may be able to just minimize Form A to get it out of the way and then resore it after the label is printed and Form B closes.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 06:28
Joined
May 21, 2018
Messages
8,529
If form B was not dialog, it would not return to the original code and finish it. That code would then need to go in Load or Open which isn't always what is needed. How do you professionals do this?
I think we are all kind of guessing what you are asking, but the following may or may not be relevant.

In Access there is something different than most other development environments to include how MSFORMS works in other VBA applications.
In most development environments when you open a form Modal it stops code execution in the calling code until the Modal form closes. This is not true in Access by itself. You must use the ACDIALOG argument. So you can do either. Call a Modal popup and stop code execution in the calling form or let code execution continue. There are advantages to do both depending on what you need to do.

In the common case you want execution to stop.

Code Execution in calling form
Call Modal, Popup Form (ACDIALOG)
Code execution given to the popup until pop up closes
Popup Form Closes
Execution resumes here in the calling code

In Access the code execution only halts in the calling form if the popup is called using the ACDIALOG windowmode argument. Calling a form that is set as pop up and modal will not automatically stop code execution. This is an important difference. There may be cases where you want to call a Modal Popup and not have code execution in the calling code halted.

The most common reason we want to halt code execution is so that you can requery the current form after an update occurs. Novice users forgetting to use the ACDIALOG wonder why the requery does not work. That is because the requery occurs immediately after the popup opens and prior to any updates.

The dilemma is to do the same as above, but allow code execution to continue in the calling form. This is often when you want to manipulate then calling form beyond simply passing in some data with OpenArgs.
If you want to do the following

Code Execution in calling form
Call Modal, Popup Form (Not ACDIALOG)
Modify properties or value of the popup to include calling methods in the pop up
Modal Popup Form Closes
Do something when Pop up closes

This is done by capturing the close event of the popup

Code:
Public WithEvents PopUp As Form_frmPopUpFormName

Public SomeCode
  docmd.openForm "frmPopUpFormName"
  set PopUp as forms("frmPopUpFormName")
  with PopUp
     set lots of properties here
  end with


Private Sub PopUp_Close()
  do some code when the popup closes
End Sub

In the above Scenario you may want to pass data back from the pop up.
In the popup you can create a custom event and raise that custom event when the pop up closes
In the Popup

'In the pop up if the OK button is clicked you want to pass one or more values back and trap that event in the Calling form

Code:
Public Event OKclicked(ReturnValue As double)

Private Sub cmdOK_Click()
    dim rtn as double
     rtn = CDbl(Me.lblReadOut.Caption)
    RaiseEvent OKclicked(rtn)
    DoCmd.Close acForm, Me.Name
End Sub

Now in the calling form you can trap this event
Code:
Private Sub PopUp_OKclicked(ReturnValue as Double)
   do something with returnvalue
end sub

The attached example provides several ways of pulling and pushing data to and from a popup.

So I am pretty sure the answer to the below is Yes, but you need to clarify what you mean because we are guessing.
If form B was not dialog, it would not return to the original code and finish it. That code would then need to go in Load or Open which isn't always what is needed. How do you professionals do this?
 

Attachments

  • PopUpFormandEvents.accdb
    728 KB · Views: 33

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 11:28
Joined
Sep 12, 2006
Messages
15,656
What I generally do is open a "popup" form like this.

Code:
'open a form and wait for it to close
Docmd.openform "form1"
While isopen("form1")
  Doevents
Wend
'... carryon

so what this does is opens the popup form without it needing to be a true dialog form, and therefore it becomes resizable. Your program will continue when that form closes, so to pass a variable back to the calling form you would have to store it in a public variable somewhere.

The doevents in the loop enable other bits of your program to run. As long as you bear in mind that your first form is still waiting for the "popup" form to close, this can give your app a much friendlier interface. It would let you check things if you weren't sure about how to deal with the popup form, for example.

Now isopen() is not a supplied function but this function below works with a form as a default, but also a table, query or report, which can be quite useful at times.

Code:
Function IsOpen(strName As String, Optional objtype As Integer = acForm)
    IsOpen = (SysCmd(acSysCmdGetObjectState, objtype, strName) <> 0)
End Function

Other than msgboxes, I very rarely use dialog forms.
 

Users who are viewing this thread

Top Bottom