Form Name with Spaces

  • Thread starter Thread starter RC-
  • Start date Start date
R

RC-

I have a couple of forms that I want to open programatically using VBA. The
form names have spaces in them (a design flaw from the beginning). How can
I call the form object to show it? Do I have to rename the form and remove
the spaces?

TIA
RC-
 
I have a couple of forms that I want to open programatically using VBA. The
form names have spaces in them (a design flaw from the beginning). How can
I call the form object to show it? Do I have to rename the form and remove
the spaces?

TIA
RC-

You should probably do so, but in the meantime you can enclose the
name in square brackets:

DoCmd.OpenForm "[My Badly Named Form]"

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
That's what I thought.

I have another question:

What the difference between

DoCmd.OpenForm "[My Badly Named Form]"

and

FORM_Some_Form_Name.Visble = True

?

Is there a preferred method, is one method "cleaner" than the other?

TIA-Again
RC-

John Vinson said:
I have a couple of forms that I want to open programatically using VBA.
The
form names have spaces in them (a design flaw from the beginning). How
can
I call the form object to show it? Do I have to rename the form and
remove
the spaces?

TIA
RC-

You should probably do so, but in the meantime you can enclose the
name in square brackets:

DoCmd.OpenForm "[My Badly Named Form]"

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
RC- said:
What the difference between

DoCmd.OpenForm "[My Badly Named Form]"

and

FORM_Some_Form_Name.Visble = True

You as a rule DO NOT want to use the 2nd syntax. There is a big difference,
as the 2nd syntax actually refers directly to the object that the ms-access
development system creates (in your example..this is would be a form with
code. If your form has no code, then you can't use the 2nd syntax). So this
class object with code is created by ms-access. So, what happens if the form
is opened two times? Or, even worse, the form is being used as a sub-form in
MORE then one form! (you have no way of know what running copy the above
refers to).

Even worse then the above problems is that if the form is NOT loaded, then
in fact your 2nd syntax will cause the form to load. However, if you now set
the form to

FORM_SomForm.Visible = False

Then, the form is still loaded, and next time when you go:

FROM_SomeForm.Visible = True

In the above, the form will display, but the on-open, and on-load events
(two very important events used for very different things) do NOT fire. As a
developer looking at the above, I have no clue if the form was already
opened, or not. (so, it makes it VERY hard to figure out what the original
developer was trying to do. Was the form already opened...but not visible?).

Worse, is that using the 2nd syntax also does NOT add the loaded form to the
Forms() collection.

Thus,

Forms.Count

Will not return he correct number of forms open. And, you can't use the
following syntax either:

strFormName = inputbox("Show last name from what form?")

msgbox forms(strFormName)("LastName")

Since your forms collection is not set correctly, then again the above code
will NOT work. So, there is a ton of problems, ton of inconsistencies, and
generally just lack of control when events fire. So, use the first
syntax....

In fact, in access 97, you could use the base clase object without creating
a new instance. In a2000 and later, you have to either define a global
var...but you can't use the base instance of custom class ojbects....and
likey the ONLY reason why you can refence the base class object when it
comes to a form is not to break old code.
 
You can only use the second statement if the Form "Some_Form_Name" has
already been opened (but hidden) previously.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top