Solved

Using variables to identify objects

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

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

679 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