Solved

form.show using a variable name

Posted on 1998-06-11
5
185 Views
Last Modified: 2010-05-03
One of my programmers is trying to load a form using a variable instead of hardcoding the form name into the procedure.   She is getting the form name from a table.  The documentation says to me that you can't use the load method with a variable instead of the form object.

Here is her code.

Private Sub DBGrid1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim MyString As String
    On Error GoTo ErrorSection
    IgColumn = DBGrid1.ColContaining(X)
    IgRow = DBGrid1.RowContaining(Y)
    VargBookmark = DBGrid1.RowBookmark(IgRow)
    FileMnu.Menu_Item = DBGrid1.Columns(IgColumn).CellValue(VargBookmark)
    FileMnu.Menu_Module = DBGrid1.Columns(1).CellValue(VargBookmark)
    lblMenu = FileMnu.Menu_Item
    lblModule = FileMnu.Menu_Module
    MyString = CStr(lblModule)       ' Create text string.
    frm3 = Mid(MyString, 1, 3)    ' Returns "warehouseNO".

    If frm3 = "frm" Then
        'MsgBox "Menu_Module empty. Should be calling form, workpad etc."
        MyString = lblModule    ' Initialize string.
        Nmefrm = Trim(MyString) 'trim spaces
        Nmefrm.Show  

Stepping thru the code I can see that the variable contains her form name, but VB doesn't like Nmefrm.Show

Is there a way to do this?

thanks

0
Comment
Question by:jnearing
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:yowkee
ID: 1463130
You could loop thru the Forms collection to compare the name and then use a form object to show.

eg.

  Dim frmTmp as Form

  For each frmTmp in Forms
      If frmTmp.Name =  Nmefrm Then
          frmTmp.Show
          Exit For
      End If
  Next


0
 
LVL 1

Author Comment

by:jnearing
ID: 1463131
That works great for forms that are loaded, but at any one time in our system there is only the current form loaded, and maybe the main form, which this code belongs to.

We will have 50 to 100 forms possibly in this application, so loading them all we think will be a drag on system resources and will make the application slow down.

0
 
LVL 4

Expert Comment

by:yowkee
ID: 1463132
jnearing,

   As I knew, there is no way to do such "dynamically" loading form. Unless you store all form names, than compare with the required name, if match , load the required form.

   Such as:

   Select Case Nmefrm
       Case "frm1"
            frm1.Show
       Case "frm2"
            frm2.Show
       :
       :
       :
   End Select

There is a previous question about this topic. You may search thru PAQ for some help.

Regards.
0
 
LVL 6

Accepted Solution

by:
anthonyc earned 200 total points
ID: 1463133
The only suggestion I can think of is doing this:

public g_colForms as collection

sub main
  set g_colForms = new collection
  g_colforms.add form1, "form1"
  g_colforms.add form2, "form2"
  g_colforms.add form3, "form3"
  .
  .
  .
end sub

and then in your application, have this code

public sub ShowForm(szForm as string)
  on local error resume next
  g_colForms(szform).show
end sub


0
 
LVL 1

Author Comment

by:jnearing
ID: 1463134
That occurred to me but not being much of a VB programmer, I was hoping there would be a cool way to do a couple lines of code instead of 100 case statements.


Thanks for your help

Jim

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

696 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