473,788 Members | 3,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing ADO conection object to form object on form instantiation

Hi Guys,

Just wanting some opinions on best method to approach this. I am
working on an Access97 db and we have two forms and an ADO connection
object to contend with.

The desired state is this-
first form has the functionality for the user to choose an MDB file to
connect to, the user does as such, and the ado connection object is
set up and the connection is opened.

secondly, there is a command button on form1 that is supposed to
instantiate an instance of form2 which has code set to run in its on
its Load event. The code that is in this load event requires the ADO
connection object created / set up in the first form.

At the time of this writing the ADO connection object is dimmed in the
first form declarations.

The second form is to load, then run the code (does some reading of
excel workbook data amongst other things), and shows its progress on
its controls (it has a lable being used as a progress bar). Then, when
the process is finished, it should close and unload itself.

The query is then: What is the best way to handle the ADO connection
object and pass it to the form2 object?

In this case I would have preferred to use a class module with events,
but access 97 doesnt support that. I am unable to move the app at this
stage to a newer version of Access, and am wondering if I should just
gut this and start it from scratch. Inheriting things can be so much
fun :-)

Your advice is always appreciated

The Frog
Jun 27 '08 #1
6 1788
I think that if

1. Form1 has a module (it seems from your description that it does)
and
2. The ADO connection is dimmed as Public Form1ADOConnect ion as
ADODB.Connectio n

then it will be available in Form2's module

as Form_Form1.Form 1ADOConnection
without your having to do anything.

Sample code which does nothing but works:

In Form1 Module:

Public Form1ADODBConne ction As ADODB.Connectio n

Private Sub Form_Load()
Set Form1ADODBConne ction = CurrentProject. Connection
Form_Form2.Visi ble = True
End Sub

In Form2 Module:

Private Sub Form_Load()
MsgBox Form_Form1.Form 1ADODBConnectio n.ConnectionStr ing
End Sub

On Jun 12, 11:10*am, The Frog <Mr.Frog.to.... @googlemail.com wrote:
Hi Guys,

Just wanting some opinions on best method to approach this. I am
working on an Access97 db and we have two forms and an ADO connection
object to contend with.

The desired state is this-
first form has the functionality for the user to choose an MDB file to
connect to, the user does as such, and the ado connection object is
set up and the connection is opened.

secondly, there is a command button on form1 that is supposed to
instantiate an instance of form2 which has code set to run in its on
its Load event. The code that is in this load event requires the ADO
connection object created / set up in the first form.

At the time of this writing the ADO connection object is dimmed in the
first form declarations.

The second form is to load, then run the code (does some reading of
excel workbook data amongst other things), and shows its progress on
its controls (it has a lable being used as a progress bar). Then, when
the process is finished, it should close and unload itself.

The query is then: What is the best way to handle the ADO connection
object and pass it to the form2 object?

In this case I would have preferred to use a class module with events,
but access 97 doesnt support that. I am unable to move the app at this
stage to a newer version of Access, and am wondering if I should just
gut this and start it from scratch. Inheriting things can be so much
fun :-)

Your advice is always appreciated

The Frog
Jun 27 '08 #2
The Frog <Mr************ @googlemail.com wrote:
>At the time of this writing the ADO connection object is dimmed in the
first form declarations.
Why not just dim it in a VBA module and declare it as global?

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
Jun 27 '08 #3
Hi Guys,

Thanks for the feedback. I appreciate the input and benefit from your
experience. The global works okay for this solution - reason being
that I may not know what the name of the parent form is. The idea was
to try and produce the Access 97 evuivalent of a class module that
could be used with feedback being shown to the user.

The second form is actually a data 'ripper' from a syndicated data
source, and what I was hoping to do was to be able to use this in
multiple different processes, just calling it (so to speak) when
needed, by passing it the needed connection for the target DB to pump
the data to. Doing this in newer versions of Access is not a problem,
just build a class module with events (so you can give feedback to
display something or react etc...), and pass the necessary details for
it to do the work. Unfortunately a form class module is not so
flexible it seems. I was hoping that there might be a way to achieve
this that would save me doing a re-write and / or duplicating the
code. Thats cool.

I was also thinking about trying the same thing with the form as with
a full class module, but instead of passing the ADO connection, simply
pass the settings for the connection to the form object (as strings -
declare public variables and use them as properties) and calling a
method to get the process rolling. Has anyone given this a go in A97?
Good / bad? Issues?

Cheers

The Frog
Jun 27 '08 #4
OK, found a simple (and somewhat obvious) solution to the problem.
Here goes:

1/ Create the desired form module with the necessary design elements
on the form - in this case a progress bar.

2/ declare all the needed parts (ie/ Global variables) as private
var's for the form

3/ declare the sub's and func's that are needed as private in the
forms code

4/ create a public function within the form that accepts the required
input parameters (in this case: (ByRef connDB as ADODB.Connectio n) as
Boolean)

5/ create a second public function that tests the required parameters
before execution and returns a go/ no go so you know whether or not to
run the actual function.

To use it, declare the form as an object and control it from there...

Works like a charm. Progress form pops up nicely for the specific
task, the bar slides across so the user can see what is going on, and
when it is finished the user knows of success or failure (and in this
case also why). Pretty sweet. Obvious really when you think about it
but sometimes you dont see the forrest for the trees.

Thanks for the input guys, it got me thinking in the right direction.
Appreciated.

Cheers

The Frog
Jun 27 '08 #5
On Jun 18, 4:20*am, The Frog <Mr.Frog.to.... @googlemail.com wrote:
OK, found a simple (and somewhat obvious) solution to the problem.
Here goes:

1/ Create the desired form module with the necessary design elements
on the form - in this case a progress bar.

2/ declare all the needed parts (ie/ Global variables) as private
var's for the form

3/ declare the sub's and func's that are needed as private in the
forms code

4/ create a public function within the form that accepts the required
input parameters (in this case: (ByRef connDB as ADODB.Connectio n) as
Boolean)

5/ create a second public function that tests the required parameters
before execution and returns a go/ no go so you know whether or not to
run the actual function.

To use it, declare the form as an object and control it from there...

Works like a charm. Progress form pops up nicely for the specific
task, the bar slides across so the user can see what is going on, and
when it is finished the user knows of success or failure (and in this
case also why). Pretty sweet. Obvious really when you think about it
but sometimes you dont see the forrest for the trees.

Thanks for the input guys, it got me thinking in the right direction.
Appreciated.

Cheers

The Frog
No side-trips to the moon?
Thanksgiving Dinners?
Tickets for the Celtics?
Lunchtime Quickie?
Jun 27 '08 #6
These are all of course necessary components of any development
process, however since they are almost mandatory I decided not to
mention them for the sake of brevity :-)

Something like this is at least a two moon trip and five quickie
development process. Trying to cut down on the turkey though - gaining
a little weight at the moment!

Cheers

The Frog
Jun 27 '08 #7

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

Similar topics

4
2171
by: Chris | last post by:
I'm trying to come up with a not-so-ugly manner of passing many command-line options between modules. I have a Steering.py file, which contains my main() and handles the getopts getting of several command-line options. Since having 5-6 additional parameters for every class instantiation or function call is obviously an ugly way to handle this, what would you folks recommend as a superior option? Maybe passing a dict of options to each...
6
22535
by: Martin | last post by:
I'd like to be able to get the name of an object instance from within a call to a method of that same object. Is this at all possible? The example below works by passing in the name of the object instance (in this case 'myDog'). Of course it would be better if I could somehow know from within write() that the name of the object instance was 'myDog' without having to pass it as a parameter. //////////////////////////////// function...
25
5064
by: Stuart Hilditch | last post by:
Hi all, I am hoping that someone with some experience developing nTier apps can give me some advice here. I am writing an nTier web app that began with a Data Access Layer (DAL), Business Logic Layer (BLL) and User Interface Layer (UIL). The problem I found with this was circular referencing...
6
5581
by: ged | last post by:
Hi, i am a oo (c#) programmer, and have not used javascript for a while and i cant work out how javascript manages its references. Object References work for simple stuff, but once i have an object collection and stanrd using it it starts to fall apart. Clearly there is something about javascript's usage of passing "By ref" that i am not getting. i have had a look on the web and found some examples, but i cant see why my code does not...
26
5694
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized several parts of the DOM, but this does not include the window object. Thank you
4
1865
by: Søren M. Olesen | last post by:
Hi Is it (any way) possible using reflection to set an indicator (property, variable, attribute,..). on an object before it actually instantiated, so that this indicator can be used in the constructor to determine how the was created, or who created the object.. ?? TIA Søren
14
4092
by: Anja | last post by:
Hi everyone, I have a sub form that references a query to get the results. However, what I want to do is filter the results further based on a certain criteria. How can I tell the sub form to filter results based on a certain criteria. I tried using the Filter and OrderBy fields in the designer but they seem to have no affect!
36
3859
by: zouyongbin | last post by:
Stanley B Lippman in his "C++ Primer" that a definition like this should not appear in a header file: int ix; The inclusion of any of these definitions in two or more files of the same program will result in a linker error complaining about multiple definitions. So this kind of definition should be avoided as much as possible. But as we know, the definition of a class is always in a header file. And we can use "#ifndef" to eliminate...
2
1881
by: WittyGuy | last post by:
Hi My class looks something like this: class Base { public: Base () {} ~Base () {} // No virtual dtor in the base class private: };
0
9498
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
10172
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...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
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
6749
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
5398
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...
0
5535
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.