Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using variables to identify objects

Posted on 1997-03-14
1
Medium Priority
?
283 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 200 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

824 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