Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2010
    Posts
    6

    Unanswered: Changing Control Source on a Form

    I have created a form that captures data regarding a certain program. I need to create that exact form for other programs as well that save to different tables.

    I copied my initial form and renamed it to reflect another program. Now I'm trying to change the control source to point to a different program table than my initial one.

    What is the easiest way in Access 2010 to change the control source for all of these fields without having to rebuild the form every time?

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    If you only need to change the RecordSource of the form, it's easy:
    Code:
    Me.RecordSource = ...
    For changing the control source you need to have a list somewhere (in a table, an array, ...) containing the names of the column of the data source. You can then use (here for text boxes):
    Code:
    Function ChangeControlSource()
    
        Dim ctl As Control
        
        For Each ctl In Me.Controls
            If ctl.ControlType = acTextBox Then ctl.ControlSource = "<Something>"
        Next
                
    End Function
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •