|
-
Apr 25th, 2005, 08:30 AM
#1
Thread Starter
Member
Global Variable Declaration In Module
I know that by using public key word I can Declare a Public Variable which can be accessed from any form or module but what i want is........
C I have a MDI Form,4 child form and A Module In My Project I have the connectivity with Access.In each and every form I want that connectivity.So One way to do this is to write code for connectivity in each form.But I dont want to do that. What I want is.......
I want to make connection with access just once in a module (using Function)
and when the MDI form is loaded the connecitivity should be done. For that I have written the following code in module
private function Con()
dim con as new ADODB.connection
dim rs as new ADODB.recordset
con.open "<string for mdb>"
rs.open "<table>"
the problem is....
in child form or in MDI form i am not able to access this variables.This variables are shown with null values. If i Use public keyword instead of dim while declaration it gives me an error like "statement out of function " or something like this.
can anyone help me to access this con and rs variables in each Form.
Is there any way to do this?
-
Apr 25th, 2005, 08:34 AM
#2
Re: Global Variable Declaration In Module
You actually answered your own question. Take con and rs out of the function, and declare them as Public variables in your module, then just use them in your function (which should also be Public).
-
Apr 26th, 2005, 07:10 AM
#3
Thread Starter
Member
Re: Global Variable Declaration In Module
if i declare con and rs outside the function vb gives me error like
"declaration is not allowed here"......
and if i declare them (function or variable) public then also an error message occurs
what should i do?
-
Apr 26th, 2005, 07:12 AM
#4
Re: Global Variable Declaration In Module
 Originally Posted by jalzaaal
if i declare con and rs outside the function vb gives me error like
"declaration is not allowed here"......
and if i declare them (function or variable) public then also an error message occurs
what should i do?
You need to declare them in the declarations section of the module. Where you are declaring them now?
-
Apr 26th, 2005, 07:14 AM
#5
Thread Starter
Member
Re: Global Variable Declaration In Module
at the very first line i have declared them
-
Apr 26th, 2005, 07:17 AM
#6
Re: Global Variable Declaration In Module
Attached is a sample module showing where, in the module, they should go.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|