How can I instantiate a parameter collection dialog

  • Thread starter Thread starter nigelf
  • Start date Start date
N

nigelf

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
 
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

Well one thing you can do is execute a loop until your instance closes.
Something like:

Set cls = New Form_dlgParamCollect
Do
DoEvents
Loop Until <InstanceIsClosed>

You'll need to devise a method of signalling that the instance is closed.
Say a global variable set in the OnClose event of the form instance.
 
hi,
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.
This is imho not possible. Use an event instead.

Form_dlgParamCollect:

Option Compare Database
Option Explicit

Public Event Closing()

Private Sub Form_Close()

RaiseEvent Closing

End Sub


Option Compare Database
Option Explicit

Dim WithEvents cls As Form_dlgParamCollect

Private Sub cmdShowDlg_Click()

Set cls = New Form_dlgParamCollect

cls.Modal = True
cls.Visible = True

MsgBox "halted? na!"

End Sub

Private Sub cls_Closing()

MsgBox "Closing... can use code here."

End Sub


mfG
--> stefan <--
 
hi Stuart,

Stuart said:
Set cls = New Form_dlgParamCollect
Do
DoEvents
Loop Until <InstanceIsClosed>
This works, but will result in a huge CPU load (50%+).
You'll need to devise a method of signalling that the instance is closed.
Say a global variable set in the OnClose event of the form instance.
Using an event is a imho a better solution.


mfG
--> stefan <--
 
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.
 
Stefan Hoffmann said:
hi,

This is imho not possible. Use an event instead.

Form_dlgParamCollect:

Option Compare Database
Option Explicit

Public Event Closing()

Private Sub Form_Close()

RaiseEvent Closing

End Sub


Option Compare Database
Option Explicit

Dim WithEvents cls As Form_dlgParamCollect

Private Sub cmdShowDlg_Click()

Set cls = New Form_dlgParamCollect

cls.Modal = True
cls.Visible = True

MsgBox "halted? na!"

End Sub

Private Sub cls_Closing()

MsgBox "Closing... can use code here."

End Sub


Clever. I never tried it that way, but it works. I do think it's simpler
just to use DoCmd.OpenForm ... acDialog, but to each his own.
 
Using an event is a imho a better solution.

I agree. I like your suggestion. I'm a bigtime user of custom events, but
that never occurred to me.
 
Thanks - an event will do it

I'm trying to make the bridge to OO, which is why Im not keen to use the
DoCmd thing which I already have working
 
Clever indeed.
I only knew of Dirks's method.
I probably would have explored:

(a) writing a separate class;

(b) using its Initialise event to open the dialog form with
DoCmd; and

(c) using its Terminate event to close the dialog.

I don't know whether that approach would have worked in the
circumstances described. But raising a custom event in a form
class is neat and not something I'd have thought of immediately.

Nice contribution.

Regards
Geoff
 
Back
Top