I was thinking this was simple, but perhaps it's not as easy as I thought.
I've looped through controls in a form many times, but what I want to do now is to loop through all controls within all forms in a database.
I tried this:
That didn't work, errored out as soon as I tried to say For Each frm in CurrentProject.AllForms
So then I tried:
And that one will loop through all the forms, but when I try to loop through the controls on the given form, it tells me:
"Can't find the form, FirstFormNameItComesTo"
Am I forgetting something simple or missing something, or is it somehow not possible to loop through the controls of each form as you're looping through form objects?
Thanks for any suggestions, references, corrections, etc..
I've looped through controls in a form many times, but what I want to do now is to loop through all controls within all forms in a database.
I tried this:
Code:
Dim frm as Form
For Each frm In CurrentProject.AllForms
If InStr(frm.Name, "MyString") Then Debug.Print "Forms|" & frm.Name
For Each ctl In Forms(frm.Name).Controls
If InStr(ctl.Name, "MyString") Then Debug.Print "Form|" & frm.Name & "|" & ctl.Name
Next ctl
Next frm
That didn't work, errored out as soon as I tried to say For Each frm in CurrentProject.AllForms
So then I tried:
Code:
Dim obj As Object
Dim frm as Form
For Each obj In CurrentProject.AllForms
If InStr(obj.Name, "MyString") Then Debug.Print "Forms|" & obj.Name
[green]'Set frm = Forms(obj.Name) '- this had problems as well, so I commented out[/green]
For Each ctl In Forms(obj.Name).Controls
If InStr(ctl.Name, "MyString") Then Debug.Print "Form|" & obj.Name & "|" & ctl.Name
Next ctl
Next obj
"Can't find the form, FirstFormNameItComesTo"
Am I forgetting something simple or missing something, or is it somehow not possible to loop through the controls of each form as you're looping through form objects?
Thanks for any suggestions, references, corrections, etc..