Solved

form.show using a variable name

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB error "Type mismatch" 2 49
Copy a row 12 57
Search combo error "Data Type Mismatch in Criteria Expression" 2 51
vbModal 12 31
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…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

914 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

16 Experts available now in Live!

Get 1:1 Help Now