473,386 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 1771
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 Form1ADOConnection as
ADODB.Connection

then it will be available in Form2's module

as Form_Form1.Form1ADOConnection
without your having to do anything.

Sample code which does nothing but works:

In Form1 Module:

Public Form1ADODBConnection As ADODB.Connection

Private Sub Form_Load()
Set Form1ADODBConnection = CurrentProject.Connection
Form_Form2.Visible = True
End Sub

In Form2 Module:

Private Sub Form_Load()
MsgBox Form_Form1.Form1ADODBConnection.ConnectionString
End Sub

On Jun 12, 11:10*am, The Frog <Mr.Frog.to....@googlemail.comwrote:
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.comwrote:
>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.Connection) 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.comwrote:
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.Connection) 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
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...
6
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...
25
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...
6
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...
26
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...
4
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...
14
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...
36
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...
2
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...

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.