Writing codes in Microsoft Access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Freddie1001
    New Member
    • Aug 2020
    • 2

    Writing codes in Microsoft Access

    Good day MMcCarthy
    Please I'm a beginner in Access programming.
    I'm developing a small application for my office use.
    On the Form, I would like to have some fields diabled based on selection from a combo.
    For instance, immediately after selecting Cars in a combo, the fields Tonnage and AuxTank should be disabled; preventing user from entering values in those two fields.
    Thank you for your support.
    Fred A.
  • isladogs
    Recognized Expert Moderator Contributor
    • Jul 2007
    • 479

    #2
    Add code to the after update event of the combo. Something like this

    Code:
    Private Sub Me.comboname_AfterUpdate()
    
    Select Case Me.comboname
    
    Case "Cars"
    Me.Tonnage.Enabled=False
    Me.AuxTank.Enabled=False
    
    Case "Lorries"
    Me.Tonnage.Enabled=True
    
    ...
    
    Case Else
    'anything not covered in the above goes here
    
    End Select
    
    End Sub

    If you have a lot of possible variations, a better way of doing this is by using the Tag property.
    Give all the controls that you want to disable the same tag value e.g. A

    Then in the after update event, loop through the controls and set Enabled=False for all the fields where tag.value=A

    Comment

    • Freddie1001
      New Member
      • Aug 2020
      • 2

      #3
      Thank you Isladogs. It worked for me. I appreciate your help.

      Comment

      • isladogs
        Recognized Expert Moderator Contributor
        • Jul 2007
        • 479

        #4
        Hi - I'd forgotten about this thread...!
        Anyway, you're welcome

        Comment

        Working...