Link to home
Start Free TrialLog in
Avatar of Jesus112398
Jesus112398

asked on

Setting objects

Please can someone tell me how to set an object so it is accessable by all sub procedures. What I mean by this is how do I write the equivalent of this only once : Set object = statement, but I could refer to object from any procedure.

Thanks
Avatar of csalves
csalves

Hi,

Create one Object Global to Your application, you can do it creating a module "Globals" then define the object.

You have to set itin your login form or in your main form_load.
After this you can use it in every modules.

bye,
Avatar of Jesus112398

ASKER

Please could you give me an example using the following criteria:

I want 5 individual procedures to access this: Form1.Command1 using f.
I would normally have to do this in each of those procedures :

Dim f As CommandButton
Set f = Form1.Command1

How would need to do this only once.
Add a module to your problem.
In this module define:
Public g_myObject as ObjectType

Now from any location in your project your can do
set g_myobject = statement



Apologies if I'm not making myself clear, but what I'm getting at is I want to be able to set the object globally only once. Which would be doing the equivalent of typing set g_myobject = statement only once and calling this from any sub procedure.
E.g.

Instead of

Public f as CommandButton

Sub Test1()
    set f = form1.command1

    f.caption = "Test1"
End Sub

Sub Test2
    set f = form1.command1

    f.caption = "Test2"
End Sub



I want:
Public f as CommandButton
Sub Test1()
    f.caption = "Test1"
End Sub

Sub Test2()
    f.caption = "Test2"
End Sub

This all possible if 'f' has been set as Form1.Command1. But I don't where to set it to make this all possible.

Sorry if all that sounded patronising, just wanted to make it as clear as poss.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Mirkwood
Mirkwood

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you. I feel quite embarrassed on how simple that is.
Thank you. Come to think of it, that's exactly what csalves was saying...