Re: Iterating all forms
- From: Ray Cacciatore <RayCacciatore@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 6 Oct 2006 10:31:02 -0700
I'm trying to iterate all controls within each form. Teh thing is that I can
iterate the form properties but I need to go one step further and iterate
each control within each form. All within an inner loop.
This code does not work:
Dim obj As AccessObject, dbs As Object
Dim ctl As Control
Dim mCount As Integer
Set dbs = Application.CurrentProject
mCount = 0
For Each obj In dbs.AllForms
If obj.Type = acForm Then
For Each ctl In obj.Controls '/// Error on this line
If InStr(1, ctl.Name, "mString") > 0 Then
Debug.Print "Form: " & frm.Name & ": " & ctl.Name
mCount = mCount + 1
End If
Next ctl
End If
Next obj
"Dirk Goldgar" wrote:
"Ray Cacciatore" <RayCacciatore@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in.
message news:BD276D3E-3C8C-4048-B4CA-45128CE9FA75@xxxxxxxxxxxxx
Can someone give me an example on how to iterate all forms.
I tried:
Dim dbs As Object
Set dbs = Application.CurrentProject
For Each frm In dbs.AllForms '/// Incompatible type error on this line
....
Next frm
but I keep getting in incompatible type error.
I'm using DAO.
Ray
You'd have to have declared frm as an AccessObject:
Dim frm As AccessObject
If you plan to do anything with the form *as an Access form*, you'll
need to open the form and act on the form using a reference to the
opened form in the Forms collection.
For example, here's a sample procedure to clear or set the
AllowDesignChanges property in all forms:
'----- start of code -----
Sub SetAllowDesignChanges(OnOrOff As Boolean)
Dim obj As AccessObject
For Each obj In CurrentProject.AllForms
DoCmd.OpenForm obj.Name, acDesign, , , , acHidden
Forms(obj.Name).AllowDesignChanges = OnOrOff
DoCmd.Close acForm, obj.Name, acSaveYes
Next obj
End Sub
'----- end of code -----
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)
- Follow-Ups:
- Re: Iterating all forms
- From: Douglas J. Steele
- Re: Iterating all forms
- References:
- Re: Iterating all forms
- From: Dirk Goldgar
- Re: Iterating all forms
- Prev by Date: Re: visual basic within Access If...Then
- Next by Date: Re: Programmatically link tables
- Previous by thread: Re: Iterating all forms
- Next by thread: Re: Iterating all forms
- Index(es):
Relevant Pages
|