Re: Iterating all forms

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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)



.



Relevant Pages

  • Object reference from string
    ... update/modify with some VB code. ... I would like to iterate ... dim _obj as object ... set _obj = SomeFunction) ...
    (microsoft.public.access.formscoding)
  • Re: Multi-value selection box issue
    ... control has a SelectedItems ... collection you can iterate: ... Dim item As ListItem ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: IE sequencing and cookie notification popups
    ... ' 10Apr04: accept cookies from hotmail. ... Dim SetWindowLong ' as object ... Const sDlgCaption = " Kookie Kruncher, ... ' notifications associated with that type of control. ...
    (microsoft.public.scripting.vbscript)
  • FYI: TS client script
    ... for TS on the machine running the script, ... the web control class was not found; ... Dim m_Tracing, m_TraceStream ... Function ArgString(ByVal argName, ByVal defaultValue) ...
    (microsoft.public.win2000.termserv.clients)
  • FYI: TS client script
    ... for TS on the machine running the script, ... the web control class was not found; ... Dim m_Tracing, m_TraceStream ... Function ArgString(ByVal argName, ByVal defaultValue) ...
    (microsoft.public.windows.terminal_services)