Solved

Using variables to identify objects

Posted on 1997-03-14
1
263 Views
Last Modified: 2006-11-17
Can I use variables to identify objects such as forms.  I know I can use activeform but I would like to use a variable to identify a form.  For example, I want to condense the following code from;
Select Case gs_Form_for_Sort_Plot
    Case "frm_KS01"
        frm_KS01.F1Book1.Sort3 command
        frm_KS01.F1Book1.SetSelection command
        frm_KS01.F1Book1.SetBorder command
    Case "frm_KS02"
        frm_KS02.F1Book1.Sort3 command
        frm_KS02.F1Book1.SetSelection command
        frm_KS02.F1Book1.SetBorder command
    Case "frm_KS03"
        frm_KS03.F1Book1.Sort3 command
        frm_KS03.F1Book1.SetSelection command
        frm_KS03.F1Book1.SetBorder command
    Case Else
        MsgBox "Error in sort."
End Select

To;

gs_Form_for_Sort_Plot.F1Book1.Sort3 command
gs_Form_for_Sort_Plot.F1Book1.SetSelection command
gs_Form_for_Sort_Plot.F1Book1.SetBorder command
0
Comment
Question by:jadekraf
1 Comment
 
LVL 5

Accepted Solution

by:
volking earned 100 total points
ID: 1424479
Sure, just pass the form name to a function/sub as TYPE FORM. Using your example ...

Select Case gs_Form_for_Sort_Plot
    Case "frm_KS01", "frm_KS02",  "frm_KS03"
        MyCode  gs_Form_for_Sort_Plot
    Case Else
        MsgBox "Error in sort."
End Select

Public Sub MyCode ( FormObj  AS FORM )
    FormObj.Sort3 command
    FormObj.SetSelection command
    FormObj.SetBorder command
End Sub
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

706 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

18 Experts available now in Live!

Get 1:1 Help Now