greying out fields

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oumba
    New Member
    • Dec 2011
    • 1

    greying out fields

    I'm a newbie at Access and am trying to get fields (like 'cs_compl', 'ec_compl', etc) in a form to grey out depending on the value entered into the 'type' field. However, 'type' is a calculated field dependent on the the value entered in the 'barcode' field. I'm using the following code:

    Code:
    Private Sub barcode_AfterUpdate()
        Me.cs_compl.Enabled = (Me.type.AfterUpdate <= 4 Or Me.type.AfterUpdate = 6 Or 7 Or 8)
        cm_compl.Enabled = (Me.type.AfterUpdate <= 4 Or Me.type.AfterUpdate = 6 Or 7 Or 8)
        ec_compl.Enabled = (4 <= Me.type.AfterUpdate >= 6)
        Me.en_compl.Enabled = (Me.type.AfterUpdate = 1 Or 8)
        Me.pe_compl.Enabled = (Me.type.AfterUpdate = 3 Or 4)
        Me.uf_compl.Enabled = (Me.type.AfterUpdate = 3)
        Me.ad_compl.Enabled = (4 <= Me.type.AfterUpdate >= 6)
    End Sub
    Thanks for any advice!
    Last edited by NeoPa; Dec 9 '11, 03:42 PM. Reason: Added mandatory [CODE] tags for you
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32661

    #2
    Unfortunately, you don't include the logic you want implemented in your question, but I'll try to reverse engineer this code and see what I can come up with. Next time please remember to ask the whole question fully if you'd like someone to spend their time trying to help you.

    Try this :

    Code:
    Private Sub Barcode_AfterUpdate()
        With Me
            .cs_compl.Enabled = (.Type <= 4) Or _
                                (.Type = 6) Or _
                                (.Type = 7) Or _
                                (.Type = 8)
            .cm_compl.Enabled = .cs_compl.Enabled
            .ec_compl.Enabled = (.Type >= 4) And (.Type <= 6)
            .en_compl.Enabled = (.Type = 1) Or (.Type = 8)
            .pe_compl.Enabled = (.Type = 3) Or (.Type = 4)
            .uf_compl.Enabled = (.Type = 3)
            .ad_compl.Enabled = .ec_compl.Enabled
        End With
    End Sub
    If it works, look at the code and see why.

    Comment

    • TheSmileyCoder
      Recognized Expert Moderator Top Contributor
      • Dec 2009
      • 2322

      #3
      2 things you seem to have misunderstood:
      Me.type.AfterUp date is not the value of the textbox Type, after it is updated. Me.type.AfterUp date is a PROPERTY, the same property that you can see specified in the Events TAB of your control. In your case it might read [EVENT PROCEDURE]

      Second you make a comparison:
      Code:
      Me.type.AfterUpdate = 6 Or 7 Or 8
      Which should further to the above have looked:
      Code:
      Me.type = 6 Or 7 Or 8
      or
      Code:
      Me.type.Value= 6 Or 7 Or 8
      The .Value is not necessary as .Value is the default property of the control.

      Not quite done yet. Another (common) misunderstandin g is that your code will compare Me.type to 6, 7 and 8. What really is happening is that you are comparing Me.type to 6, and then using the or operator between your comparision (which will be true or false) and 7 and 8. For the program it would look like this:
      Code:
      TRUE or 7 or 8
      FALSE or 7 or 8
      To make the correct comparision that I believe you are after you should use:
      Code:
      Me.type = 6 Or Me.type = 7 Or Me.type = 8
      or of course the code that NeoPa have provided for you.

      Comment

      Working...