Enumerating Through the AllForms Collection and Setting Properties For All Forms

  • Thread starter Thread starter Stuart Conner via AccessMonster.com
  • Start date Start date
S

Stuart Conner via AccessMonster.com

I'm trying to set some properties such as the BorderStyle for all the forms in a project. I think I should be able to enumerate through the AllForms collection and set the properties for each form, but I'm having trouble.

I can enumerate through the forms OK by using the following code ...

Dim myForm As AccessObject
For Each myForm In Application.CurrentProject.AllForms
MsgBox myForm.Name 'Show form name just to prove it works
Next myForm

.... and I can open a form in the loop to set its properties by adding ...

DoCmd.OpenForm myForm.Name, acDesign, , , , acWindowNormal

.... but I can't use the form name (myForm.Name) in a Forms![]... statement - the statement either wants literally the name of the form or its index number in the Forms collection.

What am I doing wrong?

Thanks for any help,

Stuart Conner
 
Once you obtain the name of the forms, you need to OpenForm in order to
modify it.

This kind of thing:

Dim accObj As AccessObject
Dim frm As Form
Dim ctl As Control
Dim strDoc As String

For Each accObj In CurrentProject.AllForms
strDoc = accObj.Name
DoCmd.OpenForm strDoc, acDesign, WindowMode:=acHidden
For Each ctl In Forms(strDoc).Controls
Debug.Print strDoc & "." & ctl.Name
Next
DoCmd.Close acForm, strDoc
Next

Set ctl = Nothing
Set frm = Nothing
Set accObj = Nothing

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

message
news:[email protected]...
 
Back
Top