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

  • Thread starter Thread starter Vlad
  • Start date Start date
V

Vlad

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
 
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!
 
Vlad said:
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
 
Marshall Barton said:
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

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 :=)
 
Back
Top