• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 260
  • Last Modified:

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
0
Jesus112398
Asked:
Jesus112398
  • 4
  • 2
1 Solution
 
csalvesCommented:
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,
0
 
Jesus112398Author Commented:
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.
0
 
MirkwoodCommented:
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



0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Jesus112398Author Commented:
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
0
 
MirkwoodCommented:
Dim f as commandbutton

sub form_load
  set f = form1.command1
end sub
0
 
Jesus112398Author Commented:
Thank you. I feel quite embarrassed on how simple that is.
0
 
Jesus112398Author Commented:
Thank you. Come to think of it, that's exactly what csalves was saying...
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now