Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Fri, 15 Aug 2008 06:08:00 -0700,    group: microsoft.public.word.vba.general        back       


UserForm.Name can and cannot be accessed   
Hi everyone,

My template contains three UserForms: UserForm1, UserForm2 and, indeed, 
UserForm3. In addition, it has this sub:

Sub ASub()
Dim aForm As UserForm

    Load UserForm1
    Load UserForm2
    Load UserForm3
    MsgBox UserForms(1).Name
    
    For Each aForm In UserForms
        If aForm.Name = "UserForm2" Then Exit For
    Next
    Call AnotherSub(aForm)    

End Sub

When I step through the code, it displays 'UserForm2' in the MsgBox. 
Stepping further, the part 'If aForm.Name = "UserForm2" Then' results in 
run-time error 438: "Object doesn't support this property or method".

Now why is that? And how can I refer to UserForm2 to pass this particular 
form as an argument to a sub? UserForms("UserForm2") is not allowed, and 
performing a test beforehand on the name of the UserForm apparently is not 
allowed either.

Thank you,
Cooz
date: Fri, 15 Aug 2008 06:08:00 -0700   author:   Cooz

Re: UserForm.Name can and cannot be accessed   
Hi Cooz,

>Now why is that?

I don't know, however:

Sub ASub()
Dim i As Long
Load UserForm1
Load UserForm2
For i = 0 To UserForms.Count - 1
   If UserForms(i).name = "UserForm2" Then Exit For
Next
Call anothersub(UserForms(i))
End Sub

Sub anothersub(x As Object)
MsgBox x.name
End Sub
--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
date: Fri, 15 Aug 2008 15:49:47 +0200   author:   Helmut Weber

Re: UserForm.Name can and cannot be accessed   
Hi Helmut,

Of course. Simple as that. Should have thought of this myself :-).

Thank you. The reason why aForm.Name yields an error where UserForms(0).Name 
doesn't still completely eludes me though.

Cooz


"Helmut Weber" wrote:

> Hi Cooz,
> 
> >Now why is that?
> 
> I don't know, however:
> 
> Sub ASub()
> Dim i As Long
> Load UserForm1
> Load UserForm2
> For i = 0 To UserForms.Count - 1
>    If UserForms(i).name = "UserForm2" Then Exit For
> Next
> Call anothersub(UserForms(i))
> End Sub
> 
> Sub anothersub(x As Object)
> MsgBox x.name
> End Sub
> --
> 
> Greetings from Bavaria, Germany
> 
> Helmut Weber, MVP WordVBA
> 
> Vista Small Business, Office XP
>
date: Fri, 15 Aug 2008 07:17:01 -0700   author:   Cooz

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us