Public Sub SetDSColHeading(Ctrl As Control, Heading As String)
' Sets the column heading for a control in Datasheet View. This is the same
' as setting the attached label's Caption.
Dim ctl As Control, intType As Integer
If Ctrl.Controls.count > 0 Then
For Each ctl In Ctrl.Controls
With ctl
On Error GoTo ErrorHandler
intType = .ControlType ' Late bound! Could raise error
On Error Resume Next
If intType = acLabel Then
' For an OptionGroup control, this could be a label
' *within* the control, rather than an attached label, so
' we need to check that the top left corner of the label
' is outside of the Ctrl control
If .Left < Ctrl.Left Or .Left >= Ctrl.Left + Ctrl.Width _
Or .top < Ctrl.top Or .top >= Ctrl.top + Ctrl.Height Then
' This is the attached label
.Caption = Heading
Exit Sub
End If
End If
End With
Next ctl
End If
' The column heading can't be set because there is no attached label.
' Take appropriate action here.
Exit Sub
ErrorHandler:
If Err.Number = 3270 Then ' Property not found
' The ControlType property is implemented by "subclasses" of the
' Control class. It's conceivable that we might be looking at a
' control that doesn't implement this property. If so, it's not
' a label control anyway, so just set intType to 0 to make the
' code skip over it.
intType = 0
Resume Next
End If
' Unknown error occurred
Err.Raise Err.Number
End Sub