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

How to walk Access object model - Control properties

P: n/a
I'm hoping someone can sanity check my understanding of the Object Model for
Forms/Controls. I'm having trouble drilling down into Control properties.

First, I have a record set with the following for a given Form:

1)Container

2)ObjectType (of each object on the Form)

3)ObjectName (of each object on the Form)

4)Property Name (of each property on the form - in every section)

Now, I want to open a form in design mode and walk the object model, trying
to match the open Form's properties with what's in the rst. (abbreviated
code and no indentation for space considerations)

Select Case rst!Container

Case "Forms"

'okay, it's a form or report

**If rst!ObjectType = "Form" Then

'it's not a control

For Each prp In frm.Properties

'don't walk each section, just match property name [1]

If prp.Name = rst!PropName Then

[do stuff with Form property]

**Else 'it's a control

For Each ctl In frm.Controls

If ctl.ControlType = rst!Ctl_ID Then

'we have match of control type

With ctl

For each prp in .Properties

If prp.Name = rst!ObjectName Then [2]

'we have match of control - e.g.

'cmdButton1, or frmSubForm1

For each varItem in .Properties

if varItem = rst!PropName Then

[do stuff with Control property]

'e.g. if it's a subform, change

'special effect; if it's a command button,

'change font

**End If

Does this look correct? [1] Can I assume that I will match the Form
property without walking each section? That is, it doesn't matter from
which section rst!PropName was taken - if I just loop through every Form
property in the open Form, I'll cover all sections. [2] will I find the the
ObjectName in ctl.Properties? I've been matching the Ctl_ID okay (i.e. 110
for a listbox) but I need to also match the name of the listbox...
Nov 12 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
"deko" <dj****@hotmail.com> wrote:

Please ignore the posting from the "starwars" persona. He has some problems.

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
Nov 12 '05 #2

P: n/a
starwars <no****@tatooine.homelinux.net> wrote:
Comments: This message did not originate from the Sender address above.
It was remailed automatically by anonymizing remailer software.


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
Nov 12 '05 #3

P: n/a
"starwars" <no****@tatooine.homelinux.net> wrote
Special thanks from us all in CDMA
From the headers of the referenced message:
From: starwars <no****@tatooine.homelinux.net>
Comments: This message did not originate
from the Sender address above.
It was remailed automatically by
anonymizing remailer software.
Please report problems or inappropriate
use to the remailer administrator at
<ab***@tatooine.homelinux.net>.
X-No-Archive: Yes


Certainly "starwars <no****@tatooine.homelinux.net>" does not speak for "us
all in CDMA" -- he/she/it speaks only for him/her/it self.
Nov 12 '05 #4

P: n/a
> Please ignore the posting from the "starwars" persona. He has some
problems.

no sweat. that's the price of a public forum... but my delete button works
fine :)

I appreciate your comment
Nov 12 '05 #5

P: n/a
As far as I know, deko, a Form must be Open (in either Form or Design view)
for you to refer to the Properties and Controls on that Form. The Forms
Container includes all forms, not just open ones, so you'll need to open the
form you have found. Your comment may indicate that you are aware of this
and have opened the Form outside the code you showed us.

I'm not certain why you keep a record of the Container for a given Form --
the only Container (except, perhaps for user-defined Containers that you add
to the Database) in which Forms reside is, not surprisingly, the Forms
Container.

You appear to be assuming that the Controls on the Form, and their
Properties will be retrieved in the same order that they are written in the
Recordset of the Table. That may not be the case -- you may need to consider
using FindFirst to compare rather than assuming the order.

A Form has Properties other than Controls. But it also has a Controls
Collection that includes only Controls. You might want to consider using
that to pick up the Controls rather than extracting only Controls from the
Form's Properties (which do include the Controls).

Larry Linson
Microsoft Access MVP


"deko" <dj****@hotmail.com> wrote in message
news:ng*****************@newssvr29.news.prodigy.co m...
I'm hoping someone can sanity check my understanding of the Object Model for Forms/Controls. I'm having trouble drilling down into Control properties.

First, I have a record set with the following for a given Form:

1)Container

2)ObjectType (of each object on the Form)

3)ObjectName (of each object on the Form)

4)Property Name (of each property on the form - in every section)

Now, I want to open a form in design mode and walk the object model, trying to match the open Form's properties with what's in the rst. (abbreviated
code and no indentation for space considerations)

Select Case rst!Container

Case "Forms"

'okay, it's a form or report

**If rst!ObjectType = "Form" Then

'it's not a control

For Each prp In frm.Properties

'don't walk each section, just match property name [1]

If prp.Name = rst!PropName Then

[do stuff with Form property]

**Else 'it's a control

For Each ctl In frm.Controls

If ctl.ControlType = rst!Ctl_ID Then

'we have match of control type

With ctl

For each prp in .Properties

If prp.Name = rst!ObjectName Then [2]

'we have match of control - e.g.

'cmdButton1, or frmSubForm1

For each varItem in .Properties

if varItem = rst!PropName Then

[do stuff with Control property]

'e.g. if it's a subform, change

'special effect; if it's a command button,

'change font

**End If

Does this look correct? [1] Can I assume that I will match the Form
property without walking each section? That is, it doesn't matter from
which section rst!PropName was taken - if I just loop through every Form
property in the open Form, I'll cover all sections. [2] will I find the the ObjectName in ctl.Properties? I've been matching the Ctl_ID okay (i.e. 110 for a listbox) but I need to also match the name of the listbox...

Nov 12 '05 #6

P: n/a
starwars <no****@tatooine.homelinux.net> wrote:
Comments: This message did not originate from the Sender address above.
It was remailed automatically by anonymizing remailer software.


Please ignore the above posting.

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
Nov 12 '05 #7

P: n/a
The Form in a Subform Control, even when displayed, is not "Open" -- it is
accessible as the Form property of the Control but does not exhibit the
attributes of an Open Form.

I think you will need some logic to determine the Form that is embedded as
the Source Object in the Subform Control, and open in separately, in Design
View.

Yes, a Subform Control does have Properties that apply to the Subform
Control in addition to the Form embedded in the Subform Control having its
own Properties.

Larry Linson
Microsoft Access MVP

"deko" <dj****@hotmail.com> wrote in message
news:MS******************@newssvr25.news.prodigy.c om...
Here's another crack at it....

Select Case rst!Container
Case "Forms"
acc.DoCmd.OpenForm rst!Parent, View:=acDesign, WindowMode:=acHidden
Set frm = acc.Forms(rst!Parent)
Select Case rst!ObjectType 'always either "Detail", "Form", the name of a Control, or the name of a SubForm
Case "Form"
For Each prp In frm.Properties
If prp.Name = rst!PropName Then
prp = rst!NewValue 'change any form property
acc.DoCmd.Save acForm, frm.Name
LogChange rst!Parent, rst!ObjectName, _
ctl.ControlType, lngOldCtl, _
rst!PropName, prp.Type, strOld, _
prp.Value, rst!Property_ID
End If
Next
Case "Detail"
'do something with Detail
Case Else 'we have a control or subform
For Each ctl In frm.Controls
If ctl.ControlType = 112 Then
'Close parent, open subform - walk controls
elsewhere - BUT - things like "SpecialEffect" are peculiar to the form as a *control* on the parent form... am I right?
ElseIf ctl.ControlType = rst!Ctl_ID Then 'e.g. 109
for TextBox
With ctl
For Each prp In ctl.Properties
If prp = rst!ObjectName Then 'e.g.
"txtLastName"
prp.Value = rst!NewValue 'e.g.
"Tahoma"
End If
Next
End With
End If
Next
End Select
Case "Reports"

Nov 12 '05 #8

P: n/a
> The Form in a Subform Control, even when displayed, is not "Open" -- it is
accessible as the Form property of the Control but does not exhibit the
attributes of an Open Form. 10-4
I think you will need some logic to determine the Form that is embedded as
the Source Object in the Subform Control, and open in separately, in Design View. see below...
Yes, a Subform Control does have Properties that apply to the Subform
Control in addition to the Form embedded in the Subform Control having its
own Properties.

10-4
Continuing with the example of trying to set the SubForm property
"SpecialEffect" on a SubForm Control - I don't believe opening the SubForm
in design mode will help since there is no SpecialEffect property for the
form itself, but only on the SubForm control.

So, I looped through each of the 5 properties like this:

For Each ctl In frm.Controls
If ctl.ControlType = 112 Then
With ctl
For Each prp In ctl.Properties
Debug.Print prp.Inherited & " (Inherited)"
Debug.Print prp.Name & " (Name)"
'Debug.Print prp.Properties & "(Properties)"
For Each varItem In prp.Properties
Debug.Print varItem & " (prp.Properties_Item)"
Next
Debug.Print prp.Type & "(Type)"
Debug.Print prp.Value & "(Value)"
Next
End With

See results below...

The problem now is identifying which property to change: the first property
returned [1] has the name of the SubForm for prp.Value, and then about the
20th [2] has SpecialEffect property, with the corresponding prp.Value [3]
that I'm after.

In the rst, there may be several ctl.ControlType = 112 (SubForms).
Therefore, I need to identify which SubForm I'm working with - prior to the
control structure "For Each prp In ctl.Properties..." - that way I can
change the right prp.Value for the right SubForm. Is there a way to
identify the control with a Control property?

There does not appear to be a "Ctl.Name", but there is:
Ctl.ItemData
Ctl.Object
Ctl.Parent
etc...

but I'm not sure how to work with these, or if they can help me identlfy
the name of the SubForm.

Alternatively, if I can rely on the order in which the properties are
returned, I could use something like this:

With ctl
For Each prp In ctl.Properties
If prp.Value = rst!ObjectName Then
Find Next prp.Name In ctl.Properties <<==== ??? pseudo code
Where prp.Name = rst!PropName <<=== ???
prp.Value = rst!NewValue
End If
Next
End If
Next
End With

Any suggestions on how to identify the Subform in question?

Thanks again for your help - I appreciate your patience with this one...

EventProcPrefix (Name)

(prp.Properties_Item)

8(Type)

frmPropertiesDataSheet(Value) <<=== * [1]

Name (Name)

(prp.Properties_Item)

8(Type)

frmPropertiesDataSheet(Value)

ControlType (Name)

(prp.Properties_Item)

2(Type)

112(Value)

SourceObject (Name)

(prp.Properties_Item)

8(Type)

frmPropertiesDataSheet(Value)

LinkChildFields (Name)

(prp.Properties_Item)

8(Type)

(Value)

LinkMasterFields (Name)

(prp.Properties_Item)

8(Type)

(Value)

StatusBarText (Name)

(prp.Properties_Item)

8(Type)

(Value)

Visible (Name)

(prp.Properties_Item)

11(Type)

True(Value)

DisplayWhen (Name)

(prp.Properties_Item)

2(Type)

0(Value)

Enabled (Name)

(prp.Properties_Item)

11(Type)

True(Value)

Locked (Name)

(prp.Properties_Item)

11(Type)

False(Value)

TabStop (Name)

(prp.Properties_Item)

11(Type)

True(Value)

TabIndex (Name)

(prp.Properties_Item)

2(Type)

0(Value)

CanGrow (Name)

(prp.Properties_Item)

11(Type)

True(Value)

CanShrink (Name)

(prp.Properties_Item)

11(Type)

False(Value)

Left (Name)

(prp.Properties_Item)

2(Type)

1514(Value)

Top (Name)

(prp.Properties_Item)

2(Type)

764(Value)

Width (Name)

(prp.Properties_Item)

2(Type)

12240(Value)

Height (Name)

(prp.Properties_Item)

2(Type)

6645(Value)

SpecialEffect (Name) <<==== * [2]

(prp.Properties_Item)

2(Type)

2(Value) <<=========== * [3]

BorderStyle (Name)

(prp.Properties_Item)

2(Type)

1(Value)

OldBorderStyle (Name)

(prp.Properties_Item)

2(Type)

1(Value)

BorderWidth (Name)

(prp.Properties_Item)

2(Type)

0(Value)

BorderLineStyle (Name)

(prp.Properties_Item)

2(Type)

0(Value)

BorderColor (Name)

(prp.Properties_Item)

3(Type)

0(Value)

Section (Name)

(prp.Properties_Item)

2(Type)

0(Value)

Tag (Name)

(prp.Properties_Item)

8(Type)

(Value)

InSelection (Name)

(prp.Properties_Item)

11(Type)

False(Value)

OnEnter (Name)

(prp.Properties_Item)

8(Type)

(Value)

OnExit (Name)

(prp.Properties_Item)

8(Type)

(Value)


Nov 12 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.