Setting ControlSource in VBA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nick AU
    New Member
    • Feb 2010
    • 2

    #1

    Setting ControlSource in VBA

    Hello,

    I am using MS Access 2003 and trying to set a textbox's ControlSource in VBA code.


    this following works fine

    Task.ControlSou rce = "[ActivityQuery_C rosstab].[Task]"

    However, if i try to set the control source using an expression like:

    txtCost.Control Source = "[ActivityQuery_C rosstab]![Total] * [ActivityQuery_C rosstab]![CostOut]

    or

    txtCost.Control Source = "[Total] * [CostOut]"

    Access tells me it cannot find the Field.

    Am I issing something in the formatting here, I have tried using Expression Builder in a Query and then copy and pasting but no good.

    Any ideas please?

    regards,

    Nick
  • nico5038
    Recognized Expert Specialist
    • Nov 2006
    • 3080

    #2
    Access tries to "bind" the field to the recordsource.
    You need a so-called unbound control and there the controlsource needs to start with a "=" like:
    txtCost.Control Source = "=[Total] * [CostOut]"

    Nic;o)

    Comment

    • Nick AU
      New Member
      • Feb 2010
      • 2

      #3
      Many thanks, a simple solution that has saved the rest of my hair!

      Nick

      Comment

      Working...