Private Sub CopyProperties(ByRef ctlCntrl As Control, ByRef ctlTargetCntrl As Control, ByVal strAppendFields As String)
'Copies properties from a source control to a target control skipping properties that produce an error
'In general does not copy control source unless it is a field in the comma separated list strAppendFields
'The optional Controlsource copy is to support displaying values form the new_obs table for Type 2 and similar forms
Dim lngMmm As Long
Dim lngI As Long
Dim a_strAppendFields() As String
On Error GoTo CopyProperties_Err
a_strAppendFields() = Split(Replace(strAppendFields, " ", ""), ",")
For lngMmm = 0 To ctlCntrl.Properties.Count - 1
Select Case ctlCntrl.Properties(lngMmm).Name
Case "Height", "Top", "Left", "Width", "Name", "ControlType", "HorizontalAnchor", "Tag", "Picture", "PictureData"
'Properties to skip, some set on create, some are read only, (tag intentionally left blank for other processing)
Case "ControlSource"
If strAppendFields <> "" Then
For lngI = 0 To UBound(a_strAppendFields())
If ctlCntrl.Properties(lngMmm).Value = a_strAppendFields(lngI) Then
ctlTargetCntrl.Properties(ctlCntrl.Properties(lngMmm).Name) = ctlCntrl.Properties(ctlCntrl.Properties(lngMmm).Name)
Exit For
End If
Next lngI
End If
Case Else
ctlTargetCntrl.Properties(ctlCntrl.Properties(lngMmm).Name) = ctlCntrl.Properties(ctlCntrl.Properties(lngMmm).Name) 'set all control properties on report to match the form
End Select
Next lngMmm
Exit Sub
CopyProperties_Err:
Select Case Err
Case 2101 'The setting you entered isn't valid for this property.
Resume Next
Case 2113 'The value you entered isn't valid for this field.
Resume Next
Case 2135 'This property is read-only and can't be set.
Resume Next
Case 2184 'The value you used for the TabIndex property isn't valid. The correct values are from 0 through 1.
Resume Next
Case 2455 'You entered an expression that has an invalid reference to the property XXXXX.
Resume Next
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description
'Resume
End Select
End Sub