Anyone know how to change change the control source for all the text boxes on a form in VBA ?
Anyone know how to change change the control source for all the text boxes on a form in VBA ?
Can you explain this? The forms record source should be either a table or a query. Is the form not bound?
I found this, which works:
In the form:
Private Sub Form_Activate()
Dim ctl As Control
For Each ctl In Me.Controls
If HasProperty(ctl, "ControlSource") Then
If Len(ctl.ControlSource) > 0 And Not ctl.ControlSource Like "=*" Then
Debug.Print ctl.ControlSource
End If
End If
Next
End Sub
general module:
Public Function HasProperty(obj As Object, strPropName As String) As Boolean
'Purpose: Return true if the object has the property.
Dim varDummy As Variant
On Error Resume Next
varDummy = obj.Properties(strPropName)
HasProperty = (Err.Number = 0)
End Function
credit: www.allenbrowne.com