Code not working to enable control based on input into another control

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PamelaP
    New Member
    • Aug 2012
    • 3

    Code not working to enable control based on input into another control

    Based on other bits of code I've found for this issue, I have this code on the After Update event of the first control (combo box POI in which "Hail" is in the set) but regardless of the input with this code, there is no change in control "Measuremen ts". Please help show me what I'm missing.

    Code:
    Private Sub POI_AfterUpdate()
    If (Me.POI = "Hail") Then
     Me.Measurements.Enabled = False
    Else
    Me.Measurements.Enabled = True
    End If
    End Sub
    Thanks!
    Last edited by zmbd; Aug 15 '12, 01:17 PM. Reason: Placed required code tags. -z
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    Typically this is because the bound column of the combobox does not have the value you've tested for...

    I would suspect that the combobox has 2 or more columns.
    The first column has the primary key such as 1, 2, 3...
    The second column has the text such as Hello; Hail; Aloha... which is what the user sees.
    The bound column is 1 for the control (set in the properties)

    So in my example.. "2 = Hail" there are a couple of ways to fix this... so try this code (change the number to match your data)

    Code:
    Option Compare Database
    Option Explicit
    
    Private Sub POI_AfterUpdate()
    Dim z_lng_cbobox_poi As Long
    '
    'Need an error trap?
    '
    'Get the value from the form control
    z_lng_cbobox_poi = Me.POI.Value
    '
    'check to see what the value was and
    'enable if the user selected the "Hail" entry
    If (z_lng_cbobox_poi = 2) Then     '<<<Note the change
     Me.Measurements.Enabled = False  
    Else
    Me.Measurements.Enabled = True
    End If
    '
    'error trap code would go here
    End Sub

    Comment

    Working...