Create a custom Forms collection object

nekkev4

New member
Local time
Today, 12:31
Joined
Apr 23, 2012
Messages
4
Create a custom Forms collection object [SOLVED]

Hi,

I am trying to prevent code duplication such as:

Code:
With Me.subForm1.Form
  .AllowAdditions = False
  .AllowDeletions = False
  .AllowEdits = False
End With
    
With Me.subForm2.Form
  .AllowAdditions = False
  .AllowDeletions = False
  .AllowEdits = False
End With

I would therefore like to create a Forms collection in order to loop through it's children.

Code:
Dim frmMySubForms as Forms

'Create a collection
'??? frmMySubForms.Add(Me.subForm1.Form)
'??? frmMySubForms.Add(Me.subForm2.Form)

'Loop through it
For Each frmSubFormForm in frmMySubForms
  With frmSubFormForm
    .AllowAdditions = False
    .AllowDeletions = False
    .AllowEdits = False
  End With
Next frmSubFormForm

Can this be done? I couldn't find any info on the net.

Thanks for your input.
 
Last edited:
Oops I guess I didn't think about it hard enough. For any one interested.

Code:
Private Sub chkAllowEdits_AfterUpdate()
    Dim colForms As Collection
    Dim frmForm As Form

    'Create a collection
    Set colForms = New Collection
    colForms.Add Me
    colForms.Add Me.subForm1.Form
    colForms.Add Me.subForm2.Form
    
    'Loop through it
    For Each frmForm In colForms
      With frmForm
        .AllowAdditions = False
        .AllowDeletions = False
        .AllowEdits = False
      End With
    Next frmForm
End Sub

I'm more used to ruby so I get a bit thrown off sometimes. :p
 

Users who are viewing this thread

Back
Top Bottom