473,289 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

How to walk Access object model - Control properties

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
8 3319
"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
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
"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
> 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
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
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
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
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
7
by: Adrian Gonzalez | last post by:
Hi, I have a database which is used for a model policy we have and i have a form where the paragraphs for the policy is put. Now i need a way in which i can highlight or underline the changes...
20
by: Olav.NET | last post by:
I am a .NET/C++ developer who is supposed to do some work with Access. I do not know much about it except for the DB part. Questions: *1* I am looking for INTENSIVE books to get quickly up to...
8
by: Joel Reinford | last post by:
I would like to build a class that has properties which can be accessed by string names or index numbers in the form of MyClass.Item("LastName"). The string names or item index values would be...
5
by: c676228 | last post by:
Hi, I guess I am confused. In aspx script, I mean (you won't use Codebehind="enrollinfo.aspx.vb", but mix code with html and code together) You can access user control's property directly. Since I...
5
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/callnetfrcom.asp The Joy of Interoperability Sometimes a revolution in programming forces you to abandon all...
26
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized...
12
by: Doug | last post by:
Hi, I learned a little about the model view presenter pattern at a conference this last week and am experimenting with it. It's working pretty well but I have a question. I am trying to use...
10
by: Les Desser | last post by:
In article <fcebdacd-2bd8-4d07-93a8-8b69d3452f3e@s50g2000hsb.googlegroups.com>, The Frog <Mr.Frog.to.you@googlemail.comMon, 14 Apr 2008 00:45:10 writes Not sure if I quite follow that. 1....
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.