Hi,
I'm trying to use a class to pass variables back and forth from a
form opened in dialog mode.
I have created a class which invokes a form in its show method, like
so:
Public Sub Show()
' This method shows the form used to get the info
If sWhereInt = "" Then
DoCmd.OpenForm sFormNameInt, acNormal, , , acFormAdd, _
acDialog
Else
DoCmd.OpenForm sFormNameInt, acNormal, , sWhereInt, _
acFormEdit, acDialog
End If
End Sub
I collect parameter values using:
Property Let SetParam(sName As String, vValue As Variant)
dParamDict(sName) = vValue
End Property
where dParamDict is a Scripting.Dictionary object which has been set on
class initialization.
I would like to define a private method (or property if necessary)
visible to the form to retrieve parameter values. All of my efforts so
far have failed.
Can anyone provide any guidance?
Many thanks,
Eric 14 2967 er***********@gmail.com wrote: Hi, I'm trying to use a class to pass variables back and forth from a form opened in dialog mode. I have created a class which invokes a form in its show method, like so:
Public Sub Show() ' This method shows the form used to get the info If sWhereInt = "" Then DoCmd.OpenForm sFormNameInt, acNormal, , , acFormAdd, _ acDialog Else DoCmd.OpenForm sFormNameInt, acNormal, , sWhereInt, _ acFormEdit, acDialog End If End Sub
I collect parameter values using:
Property Let SetParam(sName As String, vValue As Variant)
dParamDict(sName) = vValue
End Property
where dParamDict is a Scripting.Dictionary object which has been set on class initialization.
I would like to define a private method (or property if necessary) visible to the form to retrieve parameter values. All of my efforts so far have failed.
Can anyone provide any guidance?
First off, just because the form is opened by code in the class does not
mean that the form has access to private methods of the class. You have
to provide a public interface to retrieve "things" from the dParamDict
object just has you had to to add "things" to it. Without further detail
of what you have tried I would say the simplest way to retrieve
parameters is to provide a public method that takes a key as an argument
and returns the value associated with the key from the dParamDict object.
If what you are after is to make the dParamDict object available only to
the form that is opened then create a similar dParamDict object in the
form's module and set it equal to the dParamDict object of the class
after you open the form.
<er***********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com... Hi, I'm trying to use a class to pass variables back and forth from a form opened in dialog mode.
How are you going to use a dialog form? Using a dialog form means all code
STOPS and waits for the form to finish. In fact, you can't even use built in
menus here. I think you are confused between the concepts of a dialog form,
and a model form.
You can read about them here: http://www.members.shaw.ca/AlbertKal...log/Index.html
I have created a class which invokes a form in its show method, like so:
Ok, it is possible you understand the difference between model forms, and
dialog forms, but keeping the above in mind: DoCmd.OpenForm sFormNameInt, acNormal, , sWhereInt, _ acFormEdit, acDialog
Keep in mind, a this point the code will wait unter the above form is
closed, or kicked out of dialog mode. If the form is closed, then you can't
grab the values from the form...can you?
You *can* expose propeites in the above form as long as you declare them as
public. And, assuming you just read my above article, then you can go:
msgbox "My Custom Properity is " & forms("sFormNameInt").MyCustomProp
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada pl*****************@msn.com http://www.members.shaw.ca/AlbertKallal
Albert D. Kallal wrote: <er***********@gmail.com> wrote in message news:11**********************@f14g2000cwb.googlegr oups.com...
Hi, I'm trying to use a class to pass variables back and forth from a form opened in dialog mode.
How are you going to use a dialog form? Using a dialog form means all code STOPS and waits for the form to finish. In fact, you can't even use built in menus here. I think you are confused between the concepts of a dialog form, and a model form.
You can read about them here:
http://www.members.shaw.ca/AlbertKal...log/Index.html I have created a class which invokes a form in its show method, like so:
Ok, it is possible you understand the difference between model forms, and dialog forms, but keeping the above in mind: DoCmd.OpenForm sFormNameInt, acNormal, , sWhereInt, _ acFormEdit, acDialog
Keep in mind, a this point the code will wait unter the above form is closed, or kicked out of dialog mode. If the form is closed, then you can't grab the values from the form...can you?
You *can* expose propeites in the above form as long as you declare them as public. And, assuming you just read my above article, then you can go:
msgbox "My Custom Properity is " & forms("sFormNameInt").MyCustomProp
You can kick the form (opened in Dialog mode) out of Dialog mode by
setting the form's visibility to False (typically using a command button
in the form opened in Dialog mode). This leaves the form open and its
variables accessible and allows code to continue past the .OpenForm
call in the calling code so that you can grab values and then do a
DoCmd.Close on the form.
--
'---------------
'John Mishefske
'---------------
John Mishefske wrote: You can kick the form (opened in Dialog mode) out of Dialog mode by setting the form's visibility to False (typically using a command button in the form opened in Dialog mode). This leaves the form open and its variables accessible and allows code to continue past the .OpenForm call in the calling code so that you can grab values and then do a DoCmd.Close on the form.
Very clever!
--
--
Lyle
--
From ADO28.chm
ODBC Provider (MSDASQL)
You are strongly encouraged to use one of the native OLE DB Providers
instead of the Microsoft Open Database Connectivity (ODBC) Provider.
Native OLE DB Providers provide better application stability and
performance. Furthermore, native OLE DB Providers will be supported in
the future, whereas MSDASQL will not have any new features added to it,
will not be available on 64-bit, and will not be accessible from the OLE
DB NET Data Provider.
Yes, this:
----------------------------------------
If what you are after is to make the dParamDict object available only
to
the form that is opened then create a similar dParamDict object in the
form's module and set it equal to the dParamDict object of the class
after you open the form.
----------------------------------------
but how does the form actually reference that object? The object was
instatiated by the code that asked for the form, so I don't think it
exists outside that scope. That's precisely where I got hung up...
Hi,
Thanks to all for the insightful answers...
John, you're on to something, but I can't quite fit it with what I have
in my head that I want to do which is:
-> Calling routine wants to use the form to get a value or values from
the user, and cannot properly proceed without this input (hence the
need for blocking)
-> Calling routine calls dialog form wrapper function, passing setup
parameters as arguments, or if the wrapper function is in object form,
setting properties
-> wrapper function instantiates form as dialog using
DoCmd.OpenForm, ..... , acDialog
-> form now has access to private variables of wrapper function/object,
and fetches variables into fields on form
[if I were really fancy and java-esque, I'd write a middle function
that the form used to auto-fetch anything it can get out of the
wrapper... hmmm maybe I can do that]
because the form is doing the fetching, the fact that the wrapper
function and the calling function are now blocking is not a problem, as
a you point out, the calling function unblocks when you set visiblity
to false.
-> user clicks dialog-response button (e.g., OK or Cancel), which sets
the return value in the private values of the wrapper function, then
closes the form.
-> Setting the form's visibility to false unblocks the wrapper
function, which returns the requested value.
All of this was working peachy in function form until I needed to
return multiple values, and wanted to be able to use named return
values. At that point I tried to change the wrapper function to an
object and ran into the above problems. I guess I can try return my
dictionary object as output.
Anyway, any further thoughts y'all have would be mightily appreciated.
Thanks,
EE er***********@gmail.com wrote: Yes, this: ---------------------------------------- If what you are after is to make the dParamDict object available only to the form that is opened then create a similar dParamDict object in the form's module and set it equal to the dParamDict object of the class after you open the form. ----------------------------------------
but how does the form actually reference that object? The object was instatiated by the code that asked for the form, so I don't think it exists outside that scope. That's precisely where I got hung up...
The dialog form gets it's own copy of the dictionary object. The
following code outlines the procedure. Notice that the form is not
opened in dialog mode, but ends up acting like it was.
<Class code>
Private dParamDict Scripting.Dictionary
Private Sub OpenDialogForm()
Dim f As Access.Form
DoCmd.OpenForm "frmDialogForm", acNormal
Set f = Forms("frmDialogForm")
Set f.ParamDict = dParamDict
f.Modal = True
Set f = Nothing
End Sub
</Class code>
<Dialog form Code>
'set the form's Pop up property to true in the property sheet
'set the form's Border Style to Dialog in the property sheet
Private m_dParamDict As Scripting.Dictionary
Public Property Set ParamDict(dParams As Scripting.Dictionary)
Set m_dParamDict = dParams
End Property
</Dialog form Code>
A bound form in Access is a class object already. It has:
-built in ability to display its data in a GUI
-built in events
-built in data container (bound table)
-the ability to add events
-the ability to add functions, and subs, both public and private
-the ability to add object variables and constants
-persistence
-easy referencing through the Form() object
Why use anything else?
Darryl Kerkeslager
That looks like exactly what I'm trying to do, and I think that would
work nicely with the idea of the form automatically getting any values
it can from the calling function.
Only one key problem:
Setting form to modal does not cause the calling code to block.
Here's a timer after each statement:
Time started 2/9/2005 6:29:52 PM
Time after opening form 2/9/2005 6:29:52 PM
Time after set modal 2/9/2005 6:29:52 PM
(waits a couple seconds to close the form....)
Time form closed 2/9/2005 6:30:03 PM
To be honest, the lack of proper code blocking is a missing feature in
Access I've run up against a lot. I've seen people suggest that you
have the post-block code be fired by a on-close event of the form, but
I really don't like this because it means you have to unnaturally
segment your functions around places where you might want blocking
code.
Last time I tried using DoEvents and Sleep I got a fair bit of
crashiness - perhaps this has improved in Access 2003?
Blocking. The only effective way in Access (AFAIK) to cause code
execution to block is either to use MsgBox or open a form as dialog.
Plus, part of what I'm trying to do is abstract a
"getInformationFromUser" function of class that is not specific to the
form used to do so.
Any ideas on making code block? er***********@gmail.com wrote: That looks like exactly what I'm trying to do, and I think that would work nicely with the idea of the form automatically getting any values it can from the calling function.
Only one key problem:
Setting form to modal does not cause the calling code to block.
By block do you mean suspend? I don't see why you need the code
to wait for anything unless getting the dictionary object to the
dialog form is not all you wanted to do. You do realize that any
changes made to the dictionary object by the dialog form will be
reflected in the calling form.
Sorry, didn't realize I was being unclear. By blocking I do mean
suspend execution of code. Your point that since the dictionary object
on the dialog form and the on in the calling function are the same they
have the same values is well taken.
I guess that might make it work. I'll try passing a dictionary object
with my parameter values...
Thanks,
EE er***********@gmail.com wrote: Sorry, didn't realize I was being unclear. By blocking I do mean suspend execution of code. Your point that since the dictionary object on the dialog form and the on in the calling function are the same they have the same values is well taken.
I guess that might make it work. I'll try passing a dictionary object with my parameter values...
There's also the WithEvents keyword whereby the calling object can
subscribe to the dialog form's Close event and run code in the calling
class when the dialog form closes. That gives you the same 'blocking'
affect as actually opening the form in dialog mode via docmd.openform. er***********@gmail.com wrote: Blocking. The only effective way in Access (AFAIK) to cause code execution to block is either to use MsgBox or open a form as dialog.
Plus, part of what I'm trying to do is abstract a "getInformationFromUser" function of class that is not specific to the form used to do so.
Any ideas on making code block?
Other than opening the form with the acDialog option that I mentioned
in my previous post you could cycle waiting for the form to close:
Const conObjStateClosed = 0
DoCmd.OpenForm "frmReportsOutput"
Do While SysCmd(acSysCmdGetObjectState, acForm, "frmReportsOutput")
<> conObjStateClosed
DoEvents
Loop
Note that one of the lines wrapped. Beyond these two examples you'll
have to investigate the Win Sleep() API (there is one of those
isn't there? or am I thinking of BSD??).
--
'---------------
'John Mishefske
'--------------- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Tony Liu |
last post by:
Hi, I want to get the name of the calling function of an executing function,
I use the StackTrace class to do this and it seems working. However, does
anyone think that there any side effect...
|
by: Gary Miller |
last post by:
Does anyone know how to detect a modeless form on closing by the form that
invoked the modeless form?
form.Show();
|
by: mark |
last post by:
I am developing an application in .Net C# that needs to restore a
number of tool windows to some previous location and size. The problem
I have is that when I create the form and set the Location...
|
by: Bennett Haselton |
last post by:
I've noticed that if you enter the following code in the codebehind
page for an .aspx page, it won't compile because the call to
Trace.Write() is not valid except in methods of a class derived from...
|
by: Macca |
last post by:
Hi,
I have a windows form project. The form class has a number of methods in it
that i want to call from another class I have just created.
This class is a finite state machine and is created...
|
by: Bugs |
last post by:
Hi,
I wonder if anyone can help me out.
I'm building a vb.net application that has a form with a panel that
contains several other sub forms (as a collection of controls). What
I'm wanting to...
|
by: ahmad.humyn |
last post by:
I want to call a hidden form. My code goes something like in which the
main calls form1. form1 has a button which creates & calls form2 and
hides itself. Now I have a button in form2 which if...
|
by: Jeff |
last post by:
Still new to vb.net in VS2005 web developer...
What is the proper/standard way of doing the following - setting the value
of a variable in one sub and
calling it from another? E.g., as below....
|
by: =?Utf-8?B?VG9tIENvcmNvcmFu?= |
last post by:
I've been led to believe by several articles, particularly Eric Gunnerson's
C# Calling Code Dynamically, that calling a method dynamically through
Reflection was much slower than through a...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |