Link to home
Start Free TrialLog in
Avatar of ouestque
ouestqueFlag for United States of America

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
Avatar of Angelp1ay
Angelp1ay
Flag of United Kingdom of Great Britain and Northern Ireland image

Dim ctl AS Control

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)
Avatar of Rey Obrero (Capricorn1)
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
You mean if the textbox.name = "john"

then textbox.datasource = object john
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ouestque

ASKER

Thanks guys! Cap's code is the code I needed for my report!