nigelf said:
and prevent further processing???
I'm trying to use the class procedures and using the code :
Set cls = New Form_dlgParamCollect
that opens my parameter dialog.
However, subsequent code (e.g. in the open event of a form) continues to
be
processed. I know that the DoCmd.OpenForm command will achieve this, but I
would like to have the dialog associated with a Class Instance....
Thanks in advance for any help
Let me make sure I understand you. You have a form named "dlgParamCollect"
that you want to use to collect some parameters. In some event, for example
the open event of some other form, you want to open the dialog form and get
the parameter information, then proceed with other code in the calling
form's event. Is that right?
I'm not entirely sure what you're after in trying to assign the instantiated
dialog form to a class object. Possibly you want to then call various
methods and properties of the dialog form. The problem, as you've
discovered, is getting the calling code to wait until *something* happens on
the dialog form.
You might be able to accomplish this by instantiating an instance of the
form's class, as you're doing, and then looping (with DoEvents) until some
control or property of the dialog form has a specified value. However, this
is a cumbersome way to get a dialog to work.
The way I've always done this is to use DoCmd.OpenForm to open that form in
dialog mode; e.g.,
DoCmd.OpenForm "dlgParamCollect", WindowMode:=acDialog
That causes the calling code to pause until the dialog form is closed *or
hidden*. So on the dialog form I have an OK button that hides the form by
setting its Visible property to False, and a Cancel button that just closes
the form:
Private Sub cmdOK_Click()
Me.Visible = False
End Sub
Private Sub cmdCancel_Click()
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub
The code in the calling form checks, in the next line after opening the
dialog form, to see if the form is still open. If it is, then it collects
whatever information is needed from the dialog form and then closes it. So
it might look like this:
'----- begin example code for calling form -----
DoCmd.OpenForm "dlgParamCollect", WindowMode:=acDialog
If CurrentProject.AllForms("dlgParamCollect").IsLoaded Then
With Forms("dlgParamCollect")
varParam1 = .This
varParam2 = .That
varParam3 = .TheOther
End With
DoCmd.Close acForm, "dlgParamCollect", acSaveNo
Else
' Take some action because user cancelled.
End If
'----- end code for calling form -----
I'm aware that this isn't exactly what you asked for, but it is the only
clean and efficient way to do it that I know of. Of course, you could set a
Form object variable to the dialog form, and keep it open until you close
your calling form, but it's important to remember to close that hidden
instance of the form at some point.