Does and object exist?

G

grep

How do you determine whether an object exists on a form?

I wrote some code that sets BackColor on the form footer - then I
created a form that doesn't have a footer. Now I get an error when I try
to open the form. I'd like to put it in an IF, but I don't know how to
determine if the footer exists.

grep
 
A

Allen Browne

Just refer to:
Forms(0).Section(acfooter).BackColor
and use error handling to trap error 2462.
 
G

grep

I wound up just creating a header/footer and giving them no size. End of
problem. I'm still curious as to whether there's any way to determine
whether an object exists. I tried the IsObject method, but that's not it...

grep
 
B

Brendan Reynolds

If an object is a member of a collection, you can loop through the items in
the collection comparing the name of each item to the name of the object
you're looking for ...

For Each ctl In Me.Controls
If ctl.Name = strTheNameLookedFor Then
boolFoundIt = True
Exit For
End If
Next ctl

Unfortunately, form and report sections don't appear to be members of any
exposed collection. So yes, you can determine whether *most* types of
objects exist, but there doesn't seem to be any way to determine whether a
section exists other than attempting to assign a reference to the section
and trapping the error, as Allen suggests.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
G

grep

ARGH!! Ok - well, I appreciate the explanation. Funny, though, that it
should be a separate object in terms of having its own set of
properties, but not as an actual control...

Thanks to you both,

grep
 
B

Brendan Reynolds

Yes, I rather thought that sections where members of the Controls collection
myself, but a quick test proved otherwise - I looped through the Controls
collection of a form, debug printing the name of each control, and the names
of the sections were not included.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 

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

Top