By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,224 Members | 1,630 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,224 IT Pros & Developers. It's quick & easy.

Get list of the controls on a closed form

P: n/a
What is the code to create a list of the controls on a closed form in the
current database?

Thanks!

Steve
Oct 11 '08 #1
Share this Question
Share on Google+
20 Replies


P: n/a
On Sat, 11 Oct 2008 17:52:16 -0400, "Steve" <no******@nomsense.com>
wrote:

There is no easy way to do that.

-Tom.
Microsoft Access MVP

>What is the code to create a list of the controls on a closed form in the
current database?

Thanks!

Steve
Oct 11 '08 #2

P: n/a
Thanks for responding, Tom!

What is the hard way?

Steve
"Tom van Stiphout" <to*************@cox.netwrote in message
news:eh********************************@4ax.com...
On Sat, 11 Oct 2008 17:52:16 -0400, "Steve" <no******@nomsense.com>
wrote:

There is no easy way to do that.

-Tom.
Microsoft Access MVP

>>What is the code to create a list of the controls on a closed form in the
current database?

Thanks!

Steve

Oct 11 '08 #3

P: n/a
"Steve" <no******@nomsense.comwrote:
>Thanks for responding, Tom!

What is the hard way?
You open the form in design view. However that only works for MDBs. You can see
Rick Fisher's Find and Replace work this way.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
Oct 12 '08 #4

P: n/a
Thanks for responding, Tony!

What is the code for getting the list of the controls once you have the form
open in design view? You can't use:
For each Ctl In Forms("MyForm").Controls
because the Forms collection doesn't exist when no forms are open.

Further, If whatever you know works for MDBs, does it work for ACCDBs?

Steve

"Tony Toews [MVP]" <tt****@telusplanet.netwrote in message
news:t3********************************@4ax.com...
"Steve" <no******@nomsense.comwrote:
>>Thanks for responding, Tom!

What is the hard way?

You open the form in design view. However that only works for MDBs. You
can see
Rick Fisher's Find and Replace work this way.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/

Oct 12 '08 #5

P: n/a
On Sat, 11 Oct 2008 20:57:42 -0400, "Steve" <no******@nomsense.com>
wrote:

Why would it NOT work in accdb? That's about database storage, not the
forms package.

Dim ctl As Control
Dim strFormName As String

strFormName = "_test1"
DoCmd.OpenForm strFormName, acDesign
For Each ctl In Forms(strFormName)
Debug.Print ctl.Name
Next
DoCmd.Close acForm, strFormName

-Tom.
Microsoft Access MVP
>Thanks for responding, Tony!

What is the code for getting the list of the controls once you have the form
open in design view? You can't use:
For each Ctl In Forms("MyForm").Controls
because the Forms collection doesn't exist when no forms are open.

Further, If whatever you know works for MDBs, does it work for ACCDBs?

Steve

"Tony Toews [MVP]" <tt****@telusplanet.netwrote in message
news:t3********************************@4ax.com.. .
>"Steve" <no******@nomsense.comwrote:
>>>Thanks for responding, Tom!

What is the hard way?

You open the form in design view. However that only works for MDBs. You
can see
Rick Fisher's Find and Replace work this way.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
Oct 12 '08 #6

P: n/a
On Oct 11, 5:52*pm, "Steve" <nonse...@nomsense.comwrote:
What is the code to create a list of the controls on a closed form in the
current database?

Thanks!

Steve
Save the form as text. Parse the text file. Piece of cake. I'd do it
if I could think of any use for it at all. But I can't.
Oct 12 '08 #7

P: n/a
On Oct 11, 4:52 pm, "Steve" <nonse...@nomsense.comwrote:
What is the code to create a list of the controls on a closed form in the
current database?

Thanks!

Steve
Not quite the answer you asked for but might this work?

If you were to open the form from a program, but set it as hidden,
then you would be able to get an object with a collection of all the
controls. Once you have gotten from that what you want (made a list,
whatever) you could close the form?
Oct 12 '08 #8

P: n/a
On Sat, 11 Oct 2008 17:52:16 -0400, "Steve" <no******@nomsense.comwrote:
>What is the code to create a list of the controls on a closed form in the
current database?

Thanks!

Steve
Depending on your version of Access, see the documentation on the AllForms
collection in VBA help.
--

John W. Vinson [MVP]
Oct 12 '08 #9

P: n/a
MikeB <MP*****@gmail.comwrote:
>If you were to open the form from a program, but set it as hidden,
then you would be able to get an object with a collection of all the
controls. Once you have gotten from that what you want (made a list,
whatever) you could close the form?
Trouble is some forms may have external dependencies such as a combo box query based
on another form. That will likely cause an error message to come up when the form
opens that you can't get around.

Thus open the form in design view.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
Oct 12 '08 #10

P: n/a
Steve wrote:
Thanks for responding, Tony!

What is the code for getting the list of the controls once you have
the form open in design view? You can't use:
For each Ctl In Forms("MyForm").Controls
because the Forms collection doesn't exist when no forms are open.
A form opened in design view is open and therefore IS in the Forms
collection.
Further, If whatever you know works for MDBs, does it work for ACCDBs?
He didn't mean "works in MDB, not in AccDB". He meant "works in MDB, not
MDE". In this case AccDB = MDB and AccDE = MDE.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com

Oct 12 '08 #11

P: n/a
"Tony Toews [MVP]" <tt****@telusplanet.netwrote:
>You open the form in design view. However that only works for MDBs.
And ACCDBs. I'm going to have to be more careful in this respect in the future.
<smile You can't open a form or report in design view in MDE or ACCDEs.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
Oct 12 '08 #12

P: n/a
"Tony Toews [MVP]" <tt****@telusplanet.netwrote in
news:t3********************************@4ax.com:
"Steve" <no******@nomsense.comwrote:
>>Thanks for responding, Tom!

What is the hard way?

You open the form in design view.
Uh, why not just open the form in regular view? Why does it have to
be in design view? And I didn't know that the Controls collection
existed in a form open in design view.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Oct 12 '08 #13

P: n/a
"David W. Fenton" <XX*******@dfenton.com.invalidwrote:
>Thinking through this, I wonder if anyone has a position on whether
opening the form in data entry mode might not be just as easy as
design mode? What advantage would there be in using design view? No
locking?
A lot of this depends on why he is wants the control list. My assumption is that he
needs it for some of his own development requirements whatever they might be.
Therefore opening it in Edit mode saves some errors that might occur if the form was
opened in regular mode.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
Oct 13 '08 #14

P: n/a
John W. Vinson wrote:
>On Sat, 11 Oct 2008 17:52:16 -0400, "Steve" <no******@nomsense.comwrote:
>>What is the code to create a list of the controls on a closed form in the
current database?

Thanks!

Steve

Depending on your version of Access, see the documentation on the AllForms
collection in VBA help.

But an AccessObject does not have a Controls collection.
For this purpose AllForms is no more useful than
Containers!Forms.Documents.

--
Marsh
Oct 13 '08 #15

P: n/a
On Sun, 12 Oct 2008 23:10:51 -0500, Marshall Barton <ma*********@wowway.com>
wrote:
>>Depending on your version of Access, see the documentation on the AllForms
collection in VBA help.


But an AccessObject does not have a Controls collection.
For this purpose AllForms is no more useful than
Containers!Forms.Documents.
oops... sorry, you're right of course, Marshall! Sorry for jumping in without
investigating further.
--

John W. Vinson [MVP]
Oct 13 '08 #16

P: n/a
"Tony Toews [MVP]" <tt****@telusplanet.netwrote in
news:4s********************************@4ax.com:
"David W. Fenton" <XX*******@dfenton.com.invalidwrote:
>>Thinking through this, I wonder if anyone has a position on
whether opening the form in data entry mode might not be just as
easy as design mode? What advantage would there be in using design
view? No locking?

A lot of this depends on why he is wants the control list. My
assumption is that he needs it for some of his own development
requirements whatever they might be. Therefore opening it in Edit
mode saves some errors that might occur if the form was opened in
regular mode.
Did you mean to say "opening it in Design View"?

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Oct 13 '08 #17

P: n/a
"David W. Fenton" <XX*******@dfenton.com.invalidwrote:
>A lot of this depends on why he is wants the control list. My
assumption is that he needs it for some of his own development
requirements whatever they might be. Therefore opening it in Edit
mode saves some errors that might occur if the form was opened in
regular mode.

Did you mean to say "opening it in Design View"?
You are correct.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
Oct 13 '08 #18

P: n/a
Tony Toews [MVP] wrote:
>"David W. Fenton" <XX*******@dfenton.com.invalidwrote:
>>A lot of this depends on why he is wants the control list. My
assumption is that he needs it for some of his own development
requirements whatever they might be. Therefore opening it in Edit
mode saves some errors that might occur if the form was opened in
regular mode.

Did you mean to say "opening it in Design View"?

You are correct.

If the list of controls is for a prespecified form and the
form's HasModule property is true, then he could use:

Dim ctl As Control
For Each ctl In Form_myform
Debug.Print ctl.Name
Next ctl

--
Marsh
Oct 15 '08 #19

P: n/a
Marshall Barton <ma*********@wowway.comwrote in
news:ie********************************@4ax.com:
If the list of controls is for a prespecified form and the
form's HasModule property is true, then he could use:

Dim ctl As Control
For Each ctl In Form_myform
Debug.Print ctl.Name
Next ctl
Doesn't that open the form?

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Oct 15 '08 #20

P: n/a
David W. Fenton wrote:
>Marshall Barton wrote
>If the list of controls is for a prespecified form and the
form's HasModule property is true, then he could use:

Dim ctl As Control
For Each ctl In Form_myform
Debug.Print ctl.Name
Next ctl

Doesn't that open the form?

My fading memory ...

Not only does it open the form, it's opened in a data view
and it's invisible so it's not obvious that it's not in
design view.

Thanks for the reminder David.

--
Marsh
Oct 16 '08 #21

This discussion thread is closed

Replies have been disabled for this discussion.