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
Solved

form.show using a variable name

Posted on 1998-06-11
5
178 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
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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 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 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…

809 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