Solved

Setting objects

Posted on 1998-11-23
7
199 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

759 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

20 Experts available now in Live!

Get 1:1 Help Now