×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Word VBA - Using an array to view form
2

Word VBA - Using an array to view form

Word VBA - Using an array to view form

(OP)
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

RE: Word VBA - Using an array to view form

Are you wanting to have an array of user forms?

RE: Word VBA - Using an array to view form

With your other question here: thread707-1783524: Word Loop thru userforms., 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.

RE: Word VBA - Using an array to view form

(OP)
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

RE: Word VBA - Using an array to view form

"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:
A = Array(“Frmname1”,”FrmName2”,etc)

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

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


---- Andy

There is a great need for a sarcasm font.

RE: Word VBA - Using an array to view form

(OP)
Hi Andy
Again thank you for looking into this!

Ok so the solution is to declare correctly... Yes I may have omitted that smile

Herman
Say no to macros

RE: Word VBA - Using an array to view form

CODE

Public Sub ShowFormbyName(strForm As String, Optional Modal As FormShowConstants = vbmodal) 
    Call UserForms.Add(strForm).Show(Modal)
End Sub 

Call like

ShowFormbyName A(I)

RE: Word VBA - Using an array to view form

strongm's code should be (IMO):

CODE

Public Sub ShowFormbyName(strForm As String, Optional Modal As FormShowConstants = vbModal)
    Call UserForms.Add(strForm).Show(Modal)
End Sub 


---- Andy

There is a great need for a sarcasm font.

RE: Word VBA - Using an array to view form

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 ...)

RE: Word VBA - Using an array to view form

(OP)
Thanks for the code guys, I will try it tomorrow.
Its now 8 pm. Here 😀

Herman
Say no to macros

RE: Word VBA - Using an array to view form

(OP)
Ok tryed your code and it worked as expected smile
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 smile

Herman
Say no to macros

RE: Word VBA - Using an array to view form

Public Function GetFormObjectbyName(strForm As String) As Object
Set GetFormObjectbyName = UserForms.Add(strForm)
End Function

RE: Word VBA - Using an array to view form

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close