CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 1999
    Posts
    3

    Setting a form object variable using a form name string?

    In MS Access the Open form statement takes a string as the name of the form. In VB6/SQL server I have a list in a listbox of the names of many crystal report files.
    When one is picked, the chosen name is placed in the ReportFileName property of the crystal control. The name is then used to check a table of reports on SQLsrvr to
    see if it needs parameters before running the report, and if so, I want to be able to open a 'dlgformname' to get them, where formname is the same name as was chosen
    from the list. However, there seems to be no way to assign a form object reference to a form object variable using just the string name of the form somehow to resolve
    the object expression to the form class. Am I missing something? Ideally it would be functionally like:
    Dim genericform as Form
    Set genericform = New 'formname' where formname is a string variable
    genericform.show

    Is there any way to do this using a string variable containing the name of a form?


  2. #2
    Join Date
    May 1999
    Location
    Slovenia (currently: Germany)
    Posts
    249

    Re: Setting a form object variable using a form name string?

    Phuuh,

    1. ok, you can browse trough all available forms using the Forms collection:

    ' the following example changes all form captions
    Dim vForm as Variant
    for Each vForm In Forms
    vForm.Caption="Form"
    next vForm



    2. you can also get type of every variable using

    vt=VarType(var)



    3. now what you have to do is either find desired type variable or find a form and then do a select case statement

    select case
    case 1:
    set newform=new form1
    case 2:
    set newform=new form2
    end select



    But do be careful with the lifetime of objects...

    Hope it helps at least a little ( enough for a *rate* ;-) ),
    Tomaz

    ---------------------------------------------
    Tomaz Stih, B.Sc.CS [email protected]
    Ob sotoccju 10 Nameco Group
    SI-1000 Ljubljana http://www.nameco.com
    Europe



  3. #3
    Join Date
    Jul 1999
    Posts
    3

    Re: Setting a form object variable using a form name string?

    Hi Tomaz,

    Your suggestion will work for open forms, but that is not relevant to the problem because there is no instance of the form open in the module which is trying to decide to open one. As I understand it, non-loaded forms of a project do not appear in the Forms collection, and I'm talking about a large project with a lot of different forms, so the suggested solution would not work. Its the form1 form2 in your example which needs to be dynamic somehow from the available forms in the project - loaded or not.
    Cheers

    Martin


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured