Solved

form.show using a variable name

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now