dbTalk Databases Forums  

Get list of the controls on a closed form

comp.databases.ms-access comp.databases.ms-access


Discuss Get list of the controls on a closed form in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Rick Brandt
 
Posts: n/a

Default Re: Get list of the controls on a closed form - 10-12-2008 , 05:12 PM






Steve wrote:
Quote:
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.

Quote:
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





Reply With Quote
  #12  
Old   
Tony Toews [MVP]
 
Posts: n/a

Default Re: Get list of the controls on a closed form - 10-12-2008 , 05:20 PM






"Tony Toews [MVP]" <ttoews (AT) telusplanet (DOT) net> wrote:

Quote:
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/


Reply With Quote
  #13  
Old   
Tony Toews [MVP]
 
Posts: n/a

Default Re: Get list of the controls on a closed form - 10-12-2008 , 07:52 PM



"David W. Fenton" <XXXusenet (AT) dfenton (DOT) com.invalid> wrote:

Quote:
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/


Reply With Quote
  #14  
Old   
Marshall Barton
 
Posts: n/a

Default Re: Get list of the controls on a closed form - 10-12-2008 , 11:10 PM



John W. Vinson wrote:

Quote:
On Sat, 11 Oct 2008 17:52:16 -0400, "Steve" <nonsense (AT) nomsense (DOT) com> wrote:

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


Reply With Quote
  #15  
Old   
John W. Vinson
 
Posts: n/a

Default Re: Get list of the controls on a closed form - 10-13-2008 , 10:47 AM



On Sun, 12 Oct 2008 23:10:51 -0500, Marshall Barton <marshbarton (AT) wowway (DOT) com>
wrote:

Quote:
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]


Reply With Quote
  #16  
Old   
Tony Toews [MVP]
 
Posts: n/a

Default Re: Get list of the controls on a closed form - 10-13-2008 , 06:30 PM



"David W. Fenton" <XXXusenet (AT) dfenton (DOT) com.invalid> wrote:

Quote:
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/


Reply With Quote
  #17  
Old   
lyle fairfield
 
Posts: n/a

Default Re: Get list of the controls on a closed form - 10-14-2008 , 06:07 PM



On Oct 13, 7:30*pm, "Tony Toews [MVP]" <tto... (AT) telusplanet (DOT) net> wrote:
Quote:
"David W. Fenton" <XXXuse... (AT) dfenton (DOT) com.invalid> wrote:

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 athttp://www.granite.ab.ca/accsmstr.htm
* *Tony's Microsoft Access Blog -http://msmvps.com/blogs/access/
Probably opening the form is unnecessary. I've tested this on only two
forms in [Northwind 2007.accdb] and I fully expect that it needs
refinement. But I think it has promise. It is very fast. The form is
not opened, at least not in normal way of opening.

Const FilePath$ = "Temp.Txt"
Const FormatString$ = "00\ "
Const Pattern$ = " Name =""(.+?)"""
Public Function ControlNames$(ByVal FormName$)
Dim Buffer$
Dim ObjectName$
Dim Counter&
Dim FileNumber%
Dim Match As Object
Dim Matches As Object
Dim RegExp As Object
On Error GoTo ControlNamesErr:
SaveAsText acForm, FormName, FilePath
FileNumber = FreeFile()
Open FilePath For Binary As #FileNumber
Buffer = String(LOF(FileNumber), vbNullChar)
Get #FileNumber, , Buffer
Close #FileNumber
Buffer = StrConv(Buffer, vbFromUnicode)
Set RegExp = CreateObject("VBScript.RegExp")
ControlNames = Dir$(DBEngine(0)(0).Name) & vbNewLine
ControlNames = ControlNames & vbNewLine & FormName & vbNewLine
With RegExp
.Global = True
.IgnoreCase = True
.Pattern = Pattern
Set Matches = .Execute(Buffer)
For Each Match In Matches
ObjectName = Match.SubMatches(0)
Select Case ObjectName
Case "FormHeader"
Case "Detail"
Case "FormFooter"
Case Else
Counter = Counter + 1
ControlNames = ControlNames & vbNewLine & _
"Control " & Format(Counter, FormatString) & ObjectName
End Select
Next Match
End With
ControlNamesExit:
Close
Exit Function
ControlNamesErr:
MsgBox Err.Description, vbCritical, "Error " & Err.Number
Resume ControlNamesExit
End Function

Public Sub Test()
Debug.Print ControlNames("Sales Analysis Form")
End Sub

Northwind 2007.accdb

Sales Analysis Form

Control 01 Product Name
Control 02 Product Name_Label
Control 03 Employee
Control 04 Employee_Label
Control 05 Customer Name
Control 06 Customer Name_Label
Control 07 Sales
Control 08 Sales_Label
Control 09 Order Date
Control 10 Order Date_Label



Reply With Quote
  #18  
Old   
Marshall Barton
 
Posts: n/a

Default Re: Get list of the controls on a closed form - 10-15-2008 , 12:10 PM



Tony Toews [MVP] wrote:

Quote:
"David W. Fenton" <XXXusenet (AT) dfenton (DOT) com.invalid> wrote:

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


Reply With Quote
  #19  
Old   
Marshall Barton
 
Posts: n/a

Default Re: Get list of the controls on a closed form - 10-15-2008 , 07:19 PM



David W. Fenton wrote:

Quote:
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


Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.