473,727 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling a class' private method from a form

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(sNam e) = vValue

End Property

where dParamDict is a Scripting.Dicti onary 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

Nov 13 '05 #1
14 3006
rkc
er***********@g mail.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(sNam e) = vValue

End Property

where dParamDict is a Scripting.Dicti onary 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.


Nov 13 '05 #2
<er***********@ gmail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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("sFormNam eInt").MyCustom Prop
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl************* ****@msn.com
http://www.members.shaw.ca/AlbertKallal
Nov 13 '05 #3
Albert D. Kallal wrote:
<er***********@ gmail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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("sFormNam eInt").MyCustom Prop


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
'---------------
Nov 13 '05 #4
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.
Nov 13 '05 #5
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...

Nov 13 '05 #6
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

Nov 13 '05 #7
rkc
er***********@g mail.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.Dicti onary

Private Sub OpenDialogForm( )
Dim f As Access.Form
DoCmd.OpenForm "frmDialogForm" , acNormal
Set f = Forms("frmDialo gForm")
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.Dicti onary

Public Property Set ParamDict(dPara ms As Scripting.Dicti onary)
Set m_dParamDict = dParams
End Property

</Dialog form Code>


Nov 13 '05 #8
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
Nov 13 '05 #9
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?

Nov 13 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
9778
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 towards this approach such as how would it works in multi-thread. Thanks Tony
6
3229
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();
2
6611
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 and Size properties before calling the Show method, the form is not created in the Location that I set. If I call Show first everything works fine but there is excesive flicker when the Location and Size properties are set. I tried calling...
5
3092
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 System.Web.UI.Page. Two questions: 1) I don't know much about C# but I was under the impression that if certain classes and functions were available in a namespace (as the result of a "using" statement at the top of a file), then they were...
2
27257
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 and kicked off in same method where the applications' Run method is called. i.e main method in Program.cs. I'd appreciate suggesstions for calling methods in the form class from this
4
2254
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 do is call a generically named public sub in the top-most sub form in the panel. I have the name of the top-most form as a string (eg. g_TopForm = "frmCustomers") and I can reference the form with:
6
2431
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 pressed should dispose form2 and then unhide and focus form1. -------------------------------------------------- static void Main() { ..... Application.Run(new Form1());
8
12620
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. The code below draws an error as indicated. Surely there has to be a better way than to make xxx a session variable? Thanks
15
8205
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 Delegate. My testing showed that actually it was six times faster: 0.5 seconds for 100,000 iterations versus 3.1 seconds. Can anyone explain why? Something in the way I coded it? I'd appreciate any insights. Here's the code (in a Windows Form...
0
8891
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9406
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9260
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9120
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6703
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4521
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2639
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.