PC Review


Reply
Thread Tools Rate Thread

Problem with form that thinks it a commandbutton (possibly?)

 
 
Vlad
Guest
Posts: n/a
 
      22nd Feb 2006
I have two forms in my database and one of them is causing me problems
as follows in parts of my code. Easier with an example:-

If I run this:-

Debug.Print "type = " & TypeName(Form_View_Projects_Actions(2))
Debug.Print "type = " & TypeName(Form_Form1)

I get the results

type = CommandButton
type = Form_Form1

Why does Form_View_Projects_Actions(2) seem to be a CommandButton? and
how do I get it to be a form again.

TIA

Vlad

 
Reply With Quote
 
 
 
 
John Nurick
Guest
Posts: n/a
 
      23rd Feb 2006
Hi Vlad,

Probably you and VBA have different ideas on how to parse the tokens you
are passing to TypeName.

It looks as if you have forms named "Form1", "View_Projects_Actions",
and "ViewProjectsActions(2)". If so,

Typename(Form_Form1) will return the object type of Form1,
i.e. "Form_Form1"

Typename(Form_View_Projects_Actions) does the same thing

Typename(Form_View_Projects_Actions(2)) returns the object type
of the third control on View_Projects_Actions.

I don't know a way round this, except to use only alphanumeric
characters and underscores in object names. But it strikes me it's a
rather academic point: if you know to pass the form's class name to
TypeName() you already know the object type of the form!

On 22 Feb 2006 14:50:10 -0800, "Vlad" <(E-Mail Removed)>
wrote:

>I have two forms in my database and one of them is causing me problems
>as follows in parts of my code. Easier with an example:-
>
>If I run this:-
>
>Debug.Print "type = " & TypeName(Form_View_Projects_Actions(2))
>Debug.Print "type = " & TypeName(Form_Form1)
>
>I get the results
>
>type = CommandButton
>type = Form_Form1
>
>Why does Form_View_Projects_Actions(2) seem to be a CommandButton? and
>how do I get it to be a form again.
>
>TIA
>
>Vlad
>


--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.

 
Reply With Quote
 
 
 
 
Marshall Barton
Guest
Posts: n/a
 
      23rd Feb 2006
Vlad wrote:

>I have two forms in my database and one of them is causing me problems
>as follows in parts of my code. Easier with an example:-
>
>If I run this:-
>
>Debug.Print "type = " & TypeName(Form_View_Projects_Actions(2))
>Debug.Print "type = " & TypeName(Form_Form1)
>
>I get the results
>
>type = CommandButton
>type = Form_Form1
>
>Why does Form_View_Projects_Actions(2) seem to be a CommandButton? and
>how do I get it to be a form again.



What are you tring to do?

Are you aware that the syntax formobject(N) refers to the
Nth item in the form's Controls collection? Probably not,
or you wouldn't be asking your question. What did you
expect it to mean? If the (2) is part of the name of the
form, then my advice is: since spaces and other
non-alphanumeric characters in names are a pain and it hurts
when you do that, don't do it ;-)

Another point. The syntax Form_nameofform actually refers
to the form's class module, which may not be the same as a
form being displayed on the screen. Also, that syntax will
fail on light weight forms that do not have a code module.

To refer to an open form, you should use the syntax
Forms!nameofform or to refer to any form, open or not, use
the syntax CurrentProject.AllForms!nameofform

--
Marsh
MVP [MS Access]
 
Reply With Quote
 
Andibevan
Guest
Posts: n/a
 
      23rd Feb 2006

"Marshall Barton" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Vlad wrote:
>
> >I have two forms in my database and one of them is causing me problems
> >as follows in parts of my code. Easier with an example:-
> >
> >If I run this:-
> >
> >Debug.Print "type = " & TypeName(Form_View_Projects_Actions(2))
> >Debug.Print "type = " & TypeName(Form_Form1)
> >
> >I get the results
> >
> >type = CommandButton
> >type = Form_Form1
> >
> >Why does Form_View_Projects_Actions(2) seem to be a CommandButton? and
> >how do I get it to be a form again.

>
>
> What are you tring to do?
>
> Are you aware that the syntax formobject(N) refers to the
> Nth item in the form's Controls collection? Probably not,
> or you wouldn't be asking your question. What did you
> expect it to mean? If the (2) is part of the name of the
> form, then my advice is: since spaces and other
> non-alphanumeric characters in names are a pain and it hurts
> when you do that, don't do it ;-)
>
> Another point. The syntax Form_nameofform actually refers
> to the form's class module, which may not be the same as a
> form being displayed on the screen. Also, that syntax will
> fail on light weight forms that do not have a code module.
>
> To refer to an open form, you should use the syntax
> Forms!nameofform or to refer to any form, open or not, use
> the syntax CurrentProject.AllForms!nameofform
>
> --
> Marsh
> MVP [MS Access]


Thankyou Both so much - I did not realise / forgot about the naming
convention for form objects. I was trying out a number of different ways of
doing the same thing so just named my forms with (2), (3) for ease -
obviously I could use something else.

Ta very much :=)


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I make a commandbutton in Excel 'launch' a custom form? =?Utf-8?B?Y2hvcmlzbW9z?= Microsoft Excel Programming 2 12th Oct 2006 04:12 PM
How do I link a macro to a CommandButton in a custom form, want us =?Utf-8?B?Q3lib3JkZWxpYw==?= Microsoft Outlook Form Programming 11 5th Feb 2006 01:15 AM
How do set up a commandbutton on a customer form to open a web pag =?Utf-8?B?U2VhbiBNY0Nsb3NrZXk=?= Microsoft Outlook Form Programming 3 1st Feb 2006 11:16 PM
Open contact from form with CommandButton Simon Microsoft Outlook Form Programming 0 10th Sep 2004 08:05 AM
CommandButton click won't fire on form? Dave Microsoft Outlook Form Programming 5 31st Aug 2004 03:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:11 AM.