Proofread code - Make field visible based on value in another field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nedryerson
    New Member
    • Apr 2010
    • 7

    #1

    Proofread code - Make field visible based on value in another field

    Hi,

    I'm trying to get a certain field to appear only when a value from another combobox field is selected. Specifically, when "Sample Rejected" is selected in the field "PcrLabResults, " I would like the "ReasonsRejecte d" field to appear. I've set the visibility option for "ReasonsRejecte d" to "No" already. I still can't get it to work. Do I need to do anything after entering this code (ie save, click "run," etc), or will it update in the form automatically? Here's my code - please let me know what I'm doing wrong. Many thanks in advance.

    Code:
    Private Sub PcrLabResults_AfterUpdate()
      If Me.PcrLabResults = "Sample rejected" Then
        RejectionReasons.Visible = True
      End If
    End Sub

    PS - I've looked at these two threads, and still can't seem to get it right:



    Last edited by Frinavale; Apr 29 '10, 06:36 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    Well, first off, you give the control name as ReasonsRejected in your post, but use the name RejectionReason s in your code. Which is it?

    Linq ;0)>

    Comment

    • nedryerson
      New Member
      • Apr 2010
      • 7

      #3
      Sorry about that - it's "RejectionReaso ns." Still won't work...

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32669

        #4
        I would change the code slightly so that it both sets and resets the visibility status of the other control :
        Code:
        Private Sub PcrLabResults_AfterUpdate()
          RejectionReasons.Visible = (Me.PcrLabResults = "Sample rejected")
        End Sub
        That said, I see no reason why your code wouldn't work as it was. Can you try this and let us know what you get. The clearer your response, the better able we'll be to help.

        Comment

        • missinglinq
          Recognized Expert Specialist
          • Nov 2006
          • 3533

          #5
          Also
          1. What version of Access are you running?
          2. What kind of form are you using? Single, Continuous or Datasheet?
          3. What exactly do you mean by "I still can't get it to work" WHat happens?

          Linq ;0)>

          Comment

          Working...