Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2009
    Posts
    48

    Unanswered: Check Box not Behaving as Expected

    In an Access 2007 Database I have code to disable one Combo Box, three Text Boxes and oneCheck Box on Form Current event. The user can enable a control by double clicking on it. The Combo Box and Text Boxes work as expected, but the Check Box will not allow changes when enabled. Currently I have commented out the Check Box (named "chkFiled") code--The whole "chkFiled_DblClick" subroutine and the line in the Sub Form_Current that disables "chkFiled". Except for the control names, the other double-click subroutines are identical to "chkFiled_DblClick".

    Does anyone know why the Check Box behaves differently from the other controls?

    Thanks,

    Charles



    Code:
    Private Sub Form_Current()
    On Error GoTo Err_Form_Current
    
      If IsNull(Me!cmbRptType) Then Me!cmbRptType.Locked = False Else Me!cmbRptType.Locked = True
      If IsNull(Me!txtRptNum) Then Me!txtRptNum.Locked = False Else Me!txtRptNum.Locked = True
      If IsNull(Me!txtRptDate) Then Me!txtRptDate.Locked = False Else Me!txtRptDate.Locked = True
      If IsNull(Me!txtToNum) Then Me!txtToNum.Locked = False Else Me!txtToNum.Locked = True
      If IsNull(Me!chkFiled) Then Me!chkFiled.Locked = False Else Me!chkFiled.Locked = True
    
    Exit_Form_Current:
      Exit Sub
    
    Err_Form_Current:
      MsgBox Err.Description
      Resume Exit_Form_Current
    
    End Sub
    
    Private Sub chkFiled_DblClick(Cancel As Integer)
    Dim Response
    On Error GoTo Err_chkFiled_DblClick
    
      Response = MsgBox("Filed is unlocked and can be changed", vbOKOnly, "Warning")
      Me!chkFiled.Enabled = True
    Exit_chkFiled_DblClick:
      Exit Sub
    
    Err_chkFiled_DblClick:
      MsgBox Err.Description
      Resume Exit_chkFiled_DblClick
    End Sub
    Private Sub chkFiled_Exit(Cancel As Integer)
    On Error GoTo Err_chkFiled_Exit
    
      Me.txtRptNum.Enabled = True
    
    Exit_chkFiled_Exit:
      Exit Sub
    
    Err_chkFiled_Exit:
      MsgBox Err.Description
      Resume Exit_chkFiled_Exit
    
    End Sub

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    When you click on a checkbox, you automatically change its value, this is the normal behaviour for that control. Apart from that, it seems to work as expected. Here's the sequence of events when you double-click on a checkbox (see code):

    1) Enter
    2) GotFocus
    3) MouseDown
    4) MouseUp
    5) BeforeUpdate
    6) AfterUpdate
    7) Click
    8) DblClick
    --> Locked
    9) MouseUp

    Code:
    Option Compare Database
    Option Explicit
    
    Private cnt As Long
    
    Private Sub chkFiled_AfterUpdate()
        cnt = cnt + 1
        Debug.Print cnt & ") " & "AfterUpdate"
    End Sub
    
    Private Sub chkFiled_BeforeUpdate(Cancel As Integer)
        cnt = cnt + 1
        Debug.Print cnt & ") " & "BeforeUpdate"
    End Sub
    
    Private Sub chkFiled_Click()
        cnt = cnt + 1
        Debug.Print cnt & ") " & "Click"
    End Sub
    
    Private Sub chkFiled_DblClick(Cancel As Integer)
        cnt = cnt + 1
        Debug.Print cnt & ") " & "DblClick"
        Me.chkFiled.Locked = Not Me.chkFiled.Locked
        Debug.Print " --> " & IIf(Me.chkFiled.Locked = True, "Locked", "Unlocked")
    End Sub
    
    Private Sub chkFiled_Enter()
        cnt = cnt + 1
        Debug.Print cnt & ") " & "Enter"
    End Sub
    
    Private Sub chkFiled_GotFocus()
        cnt = cnt + 1
        Debug.Print cnt & ") " & "GotFocus"
    End Sub
    
    Private Sub chkFiled_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        cnt = cnt + 1
        Debug.Print cnt & ") " & "MouseDown"
    End Sub
    
    Private Sub chkFiled_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        cnt = cnt + 1
        Debug.Print cnt & ") " & "MouseUp"
    End Sub
    However, you check for a Null value in the checkbox:
    Code:
    If IsNull(Me!chkFiled)
    Are you sure that chkFiled can have a Null value?
    Have a nice day!

  3. #3
    Join Date
    Jun 2009
    Posts
    48

    Check Box Behavior

    Sinndho,

    Thanks for the prompt reply and for taking the time to write the code you posted! Perhaps a check box cannot have a null value, but with the code I posted left uncommented, I got the message "Filed is unlocked and can be changed". So the check box should have been unlocked and allowed an entry.

    I will run your posted code to try to get more insight into the events.

    Charles

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!

    Note:I never wrote that a check box cannot have a null value. I simply stated that you should check wheter in your database the checkbox chkFiled can accept a Null value or not (i.e. is it bound to a column that allows Null values?).
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •