Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word VBA - Using an array to view form 2

Status
Not open for further replies.

hermanlaksko

Programmer
Joined
Aug 26, 2001
Messages
946
Location
DK
Caon one not use an array to load or view a user form.
And if so what is the trick.
Thank you.

Herman
Say no to macros
 
Are you wanting to have an array of user forms?
 
With your other question here: thread707-1783524, maybe be it would be beneficial to know what you are trying to do/accomplish?


---- Andy

There is a great need for a sarcasm font.
 
Yes DjangMan
I have created an array however I an not able to use i for showing the formnames in this array.
Ie. A=Array(“Frmname1”,”FrmName2”,etc)
A(I).show....
Thanks

Herman
Say no to macros
 
I have created an array " of what?
If you did not declare the type, you have a Variant. If you declared you array as String, you have strings. In any event, you keep strings in your array no matter how you declare it:
[tt] A = Array(“Frmname1”,”FrmName2”,etc)[/tt]

There is a big different between:
[tt]“Frmname1”.show[/tt] - you know this does not work
and
[tt]Frmname1.Show[/tt]

You need to collect your forms (in your array) as Objects or Forms (not As Strings) to be able to say:[tt]
A(1).Show[/tt]


---- Andy

There is a great need for a sarcasm font.
 
Hi Andy
Again thank you for looking into this!

Ok so the solution is to declare correctly... Yes I may have omitted that :-)

Herman
Say no to macros
 
Code:
[blue]Public Sub ShowFormbyName(strForm As String, Optional Modal As FormShowConstants = vbmodal) 
    Call UserForms.Add(strForm).Show(Modal)
End Sub[/blue]

Call like

[tt][blue]ShowFormbyName A(I)[/blue][/tt]
 
strongm's code should be (IMO):

Code:
Public Sub ShowFormbyName([blue]strForm[/blue] As String, Optional Modal As FormShowConstants = vbModal)
    Call UserForms.Add([blue]strForm[/blue]).Show(Modal)
End [blue]Sub[/blue]


---- Andy

There is a great need for a sarcasm font.
 
It should, and I'm going to edit it ... (the userform object was an artifact of an earlier version where I was going to return the Userform from a function. Then I changed my mind ...)
 
Thanks for the code guys, I will try it tomorrow.
Its now 8 pm. Here 😀

Herman
Say no to macros
 
Ok tryed your code and it worked as expected :-)
However it looks like I am not quite out of the woods yet.

Dim Frm As UserForm, A
This gives an error - UserForms(A(I)).Load - Object required.
This works UserForms.Add(A(I)).Show (0) - Opens the form that is to be edited.
This gives an error - Set Frm = A(I) - Object required.

Any suggestions... please :-)

Herman
Say no to macros
 
Public Function GetFormObjectbyName(strForm As String) As Object
Set GetFormObjectbyName = UserForms.Add(strForm)
End Function
 
Hi StrongM
Worked like a charm - THANKS
The LOAD command I can figure out however as of now it seems that I will not need it.
Again a BIG THANKS to you both for your kind help and support.

Herman
Say no to macros
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top