Auto updating form fields

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jolaunt
    New Member
    • Apr 2010
    • 16

    Auto updating form fields

    Hi

    I have two drop down boxes in a form both looking at the same table.
    When I select info for the 1st box I want the second box to update with the same information. The code I currently have is:

    Code:
    Private Sub Ctl1_Person_Responsible_AfterUpdate()
    If "Ctl1_Person_Responsible" = 0 Then
    Ctl2_Person_Responsible.Enabled = 0
    End If
    End Sub

    This isn't working. Am I right in the 0 being the first row of data, 1 being the second row etc?

    Any help as to where I am going wrong would be great!

    Thanks
  • gershwyn
    New Member
    • Feb 2010
    • 122

    #2
    Originally posted by jolaunt
    Hi

    I have two drop down boxes in a form both looking at the same table.
    When I select info for the 1st box I want the second box to update with the same information. The code I currently have is:

    Code:
    Private Sub Ctl1_Person_Responsible_AfterUpdate()
    If "Ctl1_Person_Responsible" = 0 Then
    Ctl2_Person_Responsible.Enabled = 0
    End If
    End Sub

    This isn't working. Am I right in the 0 being the first row of data, 1 being the second row etc?

    Any help as to where I am going wrong would be great!

    Thanks
    If all you want to do is set the second control to the value of the first, try:

    Code:
    Private Sub Ctl1_Person_Responsible_AfterUpdate()
    Ctl2_Person_Responsible = Ctl1_Person_Responsible
    End Sub
    This will copy whatever value is in the first control to the second whenever the first is changed.

    As far as the code you posted, there a couple things wrong with it. First of all, you don't want quotes around your control name. What you are actually doing is comparing the string literal "Ctl1_Person_Re sponsible" to the number 0, which will never be true, and the rest of your code will never execute. Even if it did, you are then setting the enabled property of your control to zero, which will disable it.

    Comment

    • jolaunt
      New Member
      • Apr 2010
      • 16

      #3
      I was over complicating it!

      This has worked perfectly.

      Thank you

      Comment

      Working...