PC Review


Reply
Thread Tools Rate Thread

How can I instantiate a parameter collection dialog

 
 
nigelf
Guest
Posts: n/a
 
      8th Mar 2009
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
 
Reply With Quote
 
 
 
 
Stuart McCall
Guest
Posts: n/a
 
      8th Mar 2009
"nigelf" <(E-Mail Removed)> wrote in message
news:A7A4A84A-7750-499A-8D64-(E-Mail Removed)...
> 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.


 
Reply With Quote
 
Stefan Hoffmann
Guest
Posts: n/a
 
      8th Mar 2009
hi,

nigelf wrote:
> 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 <--
 
Reply With Quote
 
Stefan Hoffmann
Guest
Posts: n/a
 
      8th Mar 2009
hi Stuart,

Stuart McCall wrote:
> 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 <--
 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      8th Mar 2009
"nigelf" <(E-Mail Removed)> wrote in message
news:A7A4A84A-7750-499A-8D64-(E-Mail Removed)...
> 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.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      8th Mar 2009
"Stefan Hoffmann" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> hi,
>
> nigelf wrote:
>> 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



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.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

 
Reply With Quote
 
Stuart McCall
Guest
Posts: n/a
 
      8th Mar 2009
> 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.


 
Reply With Quote
 
nigelf
Guest
Posts: n/a
 
      8th Mar 2009
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

"Stefan Hoffmann" wrote:

> hi,
>
> nigelf wrote:
> > 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 <--
>

 
Reply With Quote
 
nigelf
Guest
Posts: n/a
 
      8th Mar 2009
Thanks everybody for your help

"nigelf" wrote:

> 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

 
Reply With Quote
 
GeoffG
Guest
Posts: n/a
 
      10th Mar 2009
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



"Stefan Hoffmann" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> hi,
>
> nigelf wrote:
>> 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 <--











 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What's 'best practice'--instantiate in the constructor or outside it for collection class? raylopez99 Microsoft C# .NET 16 13th Aug 2007 11:01 PM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Øyvind Isaksen Microsoft ASP .NET 1 18th May 2007 10:24 AM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Øyvind Isaksen Microsoft Dot NET 1 18th May 2007 10:24 AM
DB parameter collection =?Utf-8?B?Um95?= Microsoft C# .NET 1 3rd Mar 2006 08:03 PM
Collection as parameter stefantem Microsoft Excel Programming 2 13th Jan 2006 01:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:50 PM.