Solved

Setting objects

Posted on 1998-11-23
7
208 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help in WHSCRIPT 9 47
Access 2016 VB code 9 102
Excel object stays open 19 71
VBA error replacing data 6 37
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now