show userform when name is stored in variable 
Author Message
 show userform when name is stored in variable

Hi all

I have a project which will eventually be compiled to
dll.  In this I will have a number of forms and depending
on the (word) document the user has opened one of these
forms will be displayed.  Therefore I need to store the
form name in a variable and then show the form.  However,
I cannot work out how to do this.

I found an article on KB which refers to excel, eg

x = "formName"
vba.userforms.add(x).show

However when i try this it doesn't work and says object
required.  

Can anyone help please.

Thanks
Shelly



Sat, 16 Apr 2005 00:04:28 GMT  
 show userform when name is stored in variable
Hi Shelly,

You can do this if you declare the form as object and set it's value depending on which form you need.
Note that it you can't declare the object oForm as Userform, since the userforms collection only contains already loaded forms.

--------------------------------------------
Sub ShowMyForm()
Dim oForm As Object
Dim i As Integer

  'Add condition
  'to find out which form to use
  If i = 1 Then
    Set oForm = UserForm1
  Else
    Set oForm = UserForm2
  End If
  oForm.Show
  Set oForm = Nothing

End Sub
--------------------------------------------

Hope this helps,
regards,
Astrid

So that all can benefit from the discussion, please post all follow-ups to the newsgroup.
Visit the MVP Word FAQ site at http://www.mvps.org/word/


Quote:
> Hi all

> I have a project which will eventually be compiled to
> dll.  In this I will have a number of forms and depending
> on the (word) document the user has opened one of these
> forms will be displayed.  Therefore I need to store the
> form name in a variable and then show the form.  However,
> I cannot work out how to do this.

> I found an article on KB which refers to excel, eg

> x = "formName"
> vba.userforms.add(x).show

> However when i try this it doesn't work and says object
> required.  

> Can anyone help please.

> Thanks
> Shelly



Wed, 20 Apr 2005 09:33:14 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Variable(s) Reset by Showing 2nd UserForm on top 1st UserForm

2. Referencing a variable name stored in a variable

3. Where to store variables from UserForm?

4. Storing Variables 2 Display in UserForm

5. Variables stored in Range Names

6. Store the active worksheet(name) into variable

7. Setting a control who's name is stored in a variable

8. accessing control name stored in a variable

9. Storing subform name in variable when clicked

10. Reffering to Control when Name is stored in Variable


 
Powered by phpBB® Forum Software © phpBB Group