ouestque
asked on
Access:VB: Change control source of objects to its name
What is the VB code I would use to make the control source of all text and combo boxes in a report = to the objects name.
i.e. if the objects name is 100C then control source will equal 100C
i.e. if the objects name is 100C then control source will equal 100C
Sub setCtlSource()
Dim ctl As Control
DoCmd.OpenForm "FormName", acDesign
For Each ctl In Forms("formname").Controls
If ctl.ControlType = acTextBox Then
ctl.ControlSource = ctl.Name
End If
Next
DoCmd.Close acForm, "FormName", acSaveYes
End Sub
Dim ctl As Control
DoCmd.OpenForm "FormName", acDesign
For Each ctl In Forms("formname").Controls
If ctl.ControlType = acTextBox Then
ctl.ControlSource = ctl.Name
End If
Next
DoCmd.Close acForm, "FormName", acSaveYes
End Sub
You mean if the textbox.name = "john"
then textbox.datasource = object john
then textbox.datasource = object john
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks guys! Cap's code is the code I needed for my report!
For Each ctl In Me.Controls
ctl.Value = ctl.Name
Next ctl
- You might need some code to set cbo control type to value list. Prob easier to just try the code and see what errors you get and then we'll solve them ;o)