Referencing a control on a tabbed form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RonFreudenheim
    New Member
    • Jun 2023
    • 1

    Referencing a control on a tabbed form

    Hello,
    I have a tabbed form. On each tab there is a subform. On Subform1 I have a series of combo boxes whose names are Combo1, Combo2, Combo3, etc. and button that if the user clicks will write the word "Yes" in all the combo boxes on the form. The line of code that works for the first combo box is:
    Code:
    Forms!frmMain.Subform1.Form.Combo1 = "Yes"
    I want to have the same functionality on Subform2. On Subform2 I have the same line of code, except it references Subform2
    Code:
    Forms!frmMain.Subform2Form.Combo1 = "Yes"
    When I click the button the second subform I get a run time error 2465 Application defined or object defined error.

    If the line of code works on Subform1, why does it throw this error on Subform2 and what can I do to achieve the functionality I desire on Subform2?
    Last edited by NeoPa; Jun 16 '23, 09:56 PM. Reason: Added mandatory [CODE] tags.
  • cactusdata
    Recognized Expert New Member
    • Aug 2007
    • 223

    #2
    You miss a dot:
    Code:
    Forms!frmMain!Subform2.Form!Combo1 = "Yes"
    ' or, if the button is on the main form:
    Me!Subform2.Form!Combo1.Value = "Yes"
    ' or, if the button is on the subform:
    Me!Combo1.Value = "Yes"
    Also, rename your controls to something meaningful.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32662

      #3
      Indeed so. Cactus' response is perfect & I've marked it as "Best Answer" for you.

      Comment

      Working...