Solved

Setting objects

Posted on 1998-11-23
7
229 Views
Last Modified: 2010-05-03
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
Comment
Question by:Jesus112398
  • 4
  • 2
7 Comments
 
LVL 1

Expert Comment

by:csalves
ID: 1446318
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
 

Author Comment

by:Jesus112398
ID: 1446319
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
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1446320
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Jesus112398
ID: 1446321
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
 
LVL 13

Accepted Solution

by:
Mirkwood earned 60 total points
ID: 1446322
Dim f as commandbutton

sub form_load
  set f = form1.command1
end sub
0
 

Author Comment

by:Jesus112398
ID: 1446323
Thank you. I feel quite embarrassed on how simple that is.
0
 

Author Comment

by:Jesus112398
ID: 1446324
Thank you. Come to think of it, that's exactly what csalves was saying...
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA to copy paste columns form one file to other 20 91
Set email body to html using vbscript 6 49
IF ELSE Statement in Excel Macro VBA 16 75
Set WorkSheet  not Working 9 41
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question