?
Solved

Access:VB: Change control source of objects to its name

Posted on 2007-10-04
5
Medium Priority
?
503 Views
Last Modified: 2013-11-27
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
0
Comment
Question by:ouestque
5 Comments
 
LVL 11

Expert Comment

by:Angelp1ay
ID: 20014884
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
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 20014893
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
 
LVL 5

Expert Comment

by:Colemss
ID: 20014899
You mean if the textbox.name = "john"

then textbox.datasource = object john
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 20014926
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
 

Author Comment

by:ouestque
ID: 20033406
Thanks guys! Cap's code is the code I needed for my report!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question