Solved

Using variables to identify objects

Posted on 1997-03-14
1
269 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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
passing parameter in sql procedure 9 63
VB6 - Compare and highlight cell not the same 3 51
Problem to With line 4 57
Error with a code discussed on this page 5 14
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…
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 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…
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…

773 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