• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 449
  • Last Modified:

update combobox's control source dynamically on bound form

Is there a way to dynamically update an unbound combobox's control source?

I have a bound form but unbound combobox....
  • 3
  • 3
  • 2
1 Solution
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You can set the .ControlSource as needed from code, but it won't "stick". If you want to permanently change it, you'd have to open the form in Design view, make the change, then save the form.

Me.cboYourComboName.Controlsource = "[YourFieldName]"


Me.cboYourComboName.Controlsource = "txtTextBox1 + txtTextBox2"

scbdpmAuthor Commented:
LSMConsulting: after posting I found '.ControlSource' but am certainly finding that your words are correct; No sticky no update....
Realize this can be done at design time but really need to do it at run-time.
would you suggest 'INSERT"????
Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.


INSERT is a SQL Keyword that comits data to a table.

The ControlSource property specifies what field your control is bound to, or alternatively an expression that determines the data that is seen in your control.

Can you be more specific about what you are trying to do or provide an example?
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You can do it like this:

Dim frm As Form
DoCmd.OpenForm "YourForm",acDesign

Set frm = Forms("YourForm")
frm.Controls("YourControl").ControlSource = "YourNewControlSource"
DoCmd.Close acForm, "YourForm", acSaveYes

But as mariam said: Why do you need to permanently change the value of your ControlSource at runtime?
scbdpmAuthor Commented:
Here's why I need to do this:
I have a subform on my main form. It is a continuous form. On it, I've had a textbox for date and a combobx for 'Intervention'.
I've had lots of problems so have changed the combobox into a textbox as well and made them bound.
I need a way to have the user make their choice and so put an unbound textbox and combobox into the form footer. They can then type in the date and use the dropdown. My plan was to then have them click a button, have a new record created and have the two controls bound.
As an aside, becausse I was pressed for time. I was successful in having this work using the attached code.

   Dim strGroupID As String
    Dim intTopicMeasureID As Integer
    strGroupID = [Forms]![frmGroupDataEntry]![GroupID]
    intTopicMeasureID = [Forms]![frmGroupDataEntry]![subGroupTopicMeasure].[Form]![cmbTopicMeasure]
    '& "(GroupID, InterventionDate, TopicMeasureID, InterventionID) VALUES " _
    DoCmd.SetWarnings False
    DoCmd.RunSQL "INSERT INTO [tblGroupIntervention] " _
    & "(GroupID, InterventionDate, InterventionID, TopicMeasureID) VALUES " _
    & "('" & strGroupID & "', #" & txtNewInterventionDate & "#, " & cmbNewIntervention & ", " _
    & intTopicMeasureID & ")"
    DoCmd.SetWarnings True
    txtNewInterventionDate = ""
    cmbNewIntervention = ""

Open in new window

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
What was the answer you found?
scbdpmAuthor Commented:
see my last posting of 02.19.2009  

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now