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
ouestqueAsked:
Who is Participating?
 
Rey Obrero (Capricorn1)Commented:
oh sorry it is a report you are after

Sub chgRepCtlSource()
Dim ctl As Control
DoCmd.OpenReport "ReportName", acDesign
For Each ctl In Reports("Reportname").Controls
    If ctl.ControlType = acTextBox Then
        ctl.ControlSource = ctl.Name
    End If
Next
DoCmd.Close acReport, "ReportName", acSaveYes
End Sub
0
 
Angelp1ayCommented:
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)
0
 
Rey Obrero (Capricorn1)Commented:
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
0
 
ColemssCommented:
You mean if the textbox.name = "john"

then textbox.datasource = object john
0
 
ouestqueAuthor Commented:
Thanks guys! Cap's code is the code I needed for my report!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.