Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

form.show using a variable name

Posted on 1998-06-11
5
Medium Priority
?
203 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 800 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
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…
Suggested Courses

610 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