Disabling fields for one record only/ validation rule with If statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sylvio
    New Member
    • Jan 2012
    • 4

    Disabling fields for one record only/ validation rule with If statement

    Hello,

    Here is my question.

    I've got several check boxes on my form (yes/no questions for users). And one check box that says "None of the above".
    If the latter is ticked: 1) all other check boxes become disabled, and 2) Access checks if any of them were ticked and if it's true alerts user about the error.

    For #1 I wrote a code in After Update event to disable all other boxes, but it disables them for all records. How can I do it only for current record.
    For #2 I also wrote a code, but I'm wondering if it can be done using validation rule of the control. Is it possible to write an expression for validation rule to accomplish the task.

    Would appreciate any suggestions!
  • Mihail
    Contributor
    • Apr 2011
    • 759

    #2
    For #1: No way (as far as I know)

    For #2: I don't think so. Again as far as I know, the validation rule can't be a function. Here I am not so sure, sorry.

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      For 1, use the On Current event. If fires whenever the record changes. Use it to enable/disable appropriately.

      For 2, it may be possible. Try it and see. I don't have Access on this computer to confirm.

      Comment

      • Sylvio
        New Member
        • Jan 2012
        • 4

        #4
        There is no On Current event for check box control, only for the Form in general. In this case for the action to take place I need to either go to next record or push Refresh All. But I would like to have a check box that disables some of the fields while user can continue to work with other fields for this record.
        What I'm thinking is - I can use On Current event of my form, and use the check box to run Requery command, but this command takes me back to first record.

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          You don't need an On Current event for the check box. You need to use the one on the form. Use it to check the value of the checkbox and enable/disable as appropriate.

          I'm not sure why you would use the Requery command. That doesn't disable or enable anything.

          Comment

          • Sylvio
            New Member
            • Jan 2012
            • 4

            #6
            "You need to use the one on the form. Use it to check the value of the checkbox and enable/disable as appropriate."
            Yes, I've tried it as you suggested. But It doesn't disable right after I tick the check box, only when I go to the next record or Refresh All.

            Comment

            • Mihail
              Contributor
              • Apr 2011
              • 759

              #7
              From what I read until now, your goal is not to enable/disable the checkboxes. Your goal is to deny to be checked the checkbox that say "None of the above".
              Or, if this one is checked, to deny to be checked any other checkbox for a choice.
              And this can be achived with simple code:
              Code:
              Private Sub ChkChoice_1_BeforeUpdate(Cancel As Integer)
                  If ChkChoice_1 Then
                      If ChkNoChoice Then
                          MsgBox ("Message from chkChoice_1:  chkNoChoice is checked")
                          Cancel = True
                      End If
                  End If
              End Sub
              
              Private Sub chkChoice_2_BeforeUpdate(Cancel As Integer)
                  If ChkChoice_2 Then
                      If ChkNoChoice Then
                          MsgBox ("Message from chkChoice_2:  ChkNoChoice is checked")
                          Cancel = True
                      End If
                  End If
              End Sub
              
              Private Sub chkNoChoice_BeforeUpdate(Cancel As Integer)
                  If ChkNoChoice Then
                      If ChkChoice_1 Or ChkChoice_2 Then
                          MsgBox ("Message from chkNoChoice: You already made a choice")
                          Cancel = True
                      End If
                  End If
              End Sub

              Also you can use another strategy:
              Code:
              Private Sub chkChoice_1_BeforeUpdate(Cancel As Integer)
                  If ChkChoice_1 Then
                      ChkNoChoice = False
                  End If
              End Sub
              
              Private Sub ChkChoice_2_BeforeUpdate(Cancel As Integer)
                  If ChkChoice_2 Then
                      ChkNoChoice = False
                  End If
              End Sub
              
              Private Sub ChkNoChoice_BeforeUpdate(Cancel As Integer)
                  If ChkNoChoice Then
                      ChkChoice_1 = False
                      ChkChoice_2 = False
                  End If
              End Sub

              Comment

              • Rabbit
                Recognized Expert MVP
                • Jan 2007
                • 12517

                #8
                I didn't say remove your code from your other event. I only said use the On Current event. You use the On Current to solve the issue of changing records. You keep your existing code in the After Update to handle user input.

                Comment

                Working...