Return to Snippet

Revision: 13321
at April 19, 2009 12:33 by heislekw


Updated Code
Private Sub chkOther_BeforeUpdate(Cancel As Integer)
    
    ' Validation for check box with a corresponding text field. 
    ' When users check chkOther, they are encouraged to specify in txtOther what they mean. 
    ' If they enter something in txtOther and then decide to uncheck chkOther, this routine
    ' tells them the data in txtOther will be deleted. This prevents orphaned data 
    ' being stored in txtOther when chkOther isn't checked.
    
    If Not IsNull(Me.txtOther) Then     				' If txtOther has data
        If Not Me.chkOther.Value = True Or IsNull(Me.chkOther) Then     ' and the user unchecks chkOther, ask the user to confirm the change
            If MsgBox("Unchecking this will delete the information in the adjacent text field. " & _
            Chr(13) & Chr(13) & "Continue?", vbYesNo + vbDefaultButton2) = vbYes Then     
							' If the user clicks 'Yes'
                Me.txtOther = Null     			' delete the data in txtOther
                 Else                                	' Otherwise, if the user doesn't click 'Yes'
                Cancel = True                   	' don't go through with the change (i.e., cancel the update),
                Me.chkOther.Undo                      	' restore the value of chkOther to the original answer (i.e., checked)
                Exit Sub                        	' and leave this routine
            End If
        End If
    End If
    
    'Check the final value in chkOther to determine whether to enable or disable txtOther.
    'If chkOther is True (i.e., checked), set txtOther's enabled property to True (i.e., -1).
    'If chkOther <> True (i.e., it's unchecked), set txtOther's enabled property to False (i.e., 0).

    Me.txtOther.Enabled = IIf(Me.chkOther = True, -1, 0)
     
End Sub

Revision: 13320
at April 19, 2009 12:23 by heislekw


Updated Code
Private Sub chkOther_BeforeUpdate(Cancel As Integer)
    
    ' Validation for check box with a corresponding text field. 
    ' If the user checks chkOther, they are encouraged to specify in txtOther what they mean. 
    ' If they enter something in txtOther and then decide to uncheck chkOther, this routine
    ' tells them they are about to delete the value in txtOther. This prevents orphaned data 
    ' being stored in txtOther when chkOther isn't checked.
    
    If Not IsNull(Me.txtOther) Then     				' If txtOther has data
        If Not Me.chkOther.Value = True Or IsNull(Me.chkOther) Then     ' and the user unchecks chkOther, ask the user to confirm the change
            If MsgBox("Unchecking this will delete the information in the adjacent text field. " & _
            Chr(13) & Chr(13) & "Continue?", vbYesNo + vbDefaultButton2) = vbYes Then     
							' If the user clicks 'Yes'
                Me.txtOther = Null     			' delete the data in txtOther
                 Else                                	' Otherwise, if the user doesn't click 'Yes'
                Cancel = True                   	' don't go through with the change (i.e., cancel the update),
                Me.chkOther.Undo                      	' restore the value of chkOther to the original answer (i.e., checked)
                Exit Sub                        	' and leave this routine
            End If
        End If
    End If
    
    'Check the final value in chkOther to determine whether to enable or disable txtOther.
    'If chkOther is True (i.e., checked), set txtOther's enabled property to True (i.e., -1).
    'If chkOther <> True (i.e., it's unchecked), set txtOther's enabled property to False (i.e., 0).

    Me.txtOther.Enabled = IIf(Me.chkOther = True, -1, 0)
     
End Sub

Revision: 13319
at April 19, 2009 12:22 by heislekw


Updated Code
Private Sub chkOther_BeforeUpdate(Cancel As Integer)
    
    ' Validation for check box with a corresponding text field. 
    ' If the user checks chkOther, they are encouraged to specify in txtOther what they mean. 
    ' If they enter something in txtOther and then decide to uncheck chkOther, this routine
    ' tells them they are about to delete the value in txtOther. This prevents orphaned data 
    ' being stored in txtOther when chkOther isn't checked.
    
    If Not IsNull(Me.txtOther) Then     				' If txtOther has data
        If Not Me.chkOther.Value = True Or IsNull(Me.chkOther) Then     ' and the user unchecks chkOther, ask the user to confirm the change
            If MsgBox("Unchecking this will delete the information in the adjacent text field. " & _
            Chr(13) & Chr(13) & "Continue?", vbYesNo + vbDefaultButton2) = vbYes Then     
							' If the user clicks 'Yes'
                Me.txtOther = Null     			' delete the data in txtOther
                 Else                                				' Otherwise, if the user doesn't click 'Yes'
                Cancel = True                   				' don't go through with the change (i.e., cancel the update),
                Me.chkOther.Undo                      			' restore the value of chkOther to the original answer (i.e., checked)
                Exit Sub                        				' and leave this routine
            End If
        End If
    End If
    
    'Check the final value in chkOther to determine whether to enable or disable txtOther.
    'If chkOther is True (i.e., checked), set txtOther's enabled property to True (i.e., -1).
    'If chkOther <> True (i.e., it's unchecked), set txtOther's enabled property to False (i.e., 0).

    Me.txtOther.Enabled = IIf(Me.chkOther = True, -1, 0)
     
End Sub

Revision: 13318
at April 19, 2009 12:22 by heislekw


Updated Code
Private Sub chkOther_BeforeUpdate(Cancel As Integer)
    
    ' Validation for check box with a corresponding text field. 
    ' If the user checks chkOther, they are encouraged to specify in txtOther what they mean. 
    ' If they enter something in txtOther and then decide to uncheck chkOther, this routine
    ' tells them they are about to delete the value in txtOther. This prevents orphaned data 
    ' being stored in txtOther when chkOther isn't checked.
    
    If Not IsNull(Me.txtOther) Then     				' If txtOther has data
        If Not Me.chkOther.Value = True Or IsNull(Me.chkOther) Then     ' and the user unchecks chkOther, ask the user to confirm the change
            If MsgBox("Unchecking this will delete the information in the adjacent text field. " & _
            Chr(13) & Chr(13) & "Continue?", vbYesNo + vbDefaultButton2) = vbYes Then     
							' If the user clicks 'Yes'
                Me.txtOther = Null     				' delete the data in txtOther
                 Else                                				' Otherwise, if the user doesn't click 'Yes'
                Cancel = True                   				' don't go through with the change (i.e., cancel the update),
                Me.chkOther.Undo                      			' restore the value of chkOther to the original answer (i.e., checked)
                Exit Sub                        				' and leave this routine
            End If
        End If
    End If
    
    'Check the final value in chkOther to determine whether to enable or disable txtOther.
    'If chkOther is True (i.e., checked), set txtOther's enabled property to True (i.e., -1).
    'If chkOther <> True (i.e., it's unchecked), set txtOther's enabled property to False (i.e., 0).

    Me.txtOther.Enabled = IIf(Me.chkOther = True, -1, 0)
     
End Sub

Revision: 13317
at April 19, 2009 12:20 by heislekw


Updated Code
Private Sub chkOther_BeforeUpdate(Cancel As Integer)
    
    ' Validation for check box with a corresponding text field. 
    ' If the user checks chkOther, they are encouraged to specify in txtOther what they mean. 
    ' If they enter something in txtOther and then decide to uncheck chkOther, this routine
    ' tells them they are about to delete the value in txtOther.
    
    If Not IsNull(Me.txtOther) Then     				' If txtOther has data
        If Not Me.chkOther.Value = True Or IsNull(Me.chkOther) Then     ' and the user unchecks chkOther, ask the user to confirm the change
            If MsgBox("Unchecking this will delete the information in the adjacent text field. " & _
            Chr(13) & Chr(13) & "Continue?", vbYesNo + vbDefaultButton2) = vbYes Then     
							' If the user clicks 'Yes'
                Me.txtOther = Null     				' delete the data in txtOther
                 Else                                				' Otherwise, if the user doesn't click 'Yes'
                Cancel = True                   				' don't go through with the change (i.e., cancel the update),
                Me.chkOther.Undo                      			' restore the value of chkOther to the original answer (i.e., checked)
                Exit Sub                        				' and leave this routine
            End If
        End If
    End If
    
    'Check the final value in chkOther to determine whether to enable or disable txtOther.
    'If chkOther is True (i.e., checked), set txtOther's enabled property to True (i.e., -1).
    'If chkOther <> True (i.e., it's unchecked), set txtOther's enabled property to False (i.e., 0).

    Me.txtOther.Enabled = IIf(Me.chkOther = True, -1, 0)
     
End Sub

Revision: 13316
at April 19, 2009 12:15 by heislekw


Updated Code
Private Sub chkOther_BeforeUpdate(Cancel As Integer)
    
    ' Validation for check box with specify field
    
    If Not IsNull(Me.txtOther) Then           ' If txtOther has data
        If Not Me.chkOther.Value = True Or IsNull(Me.chkOther) Then  ' and the user unchecks chkOther                                                 ' ask the user to confirm the change.
            If MsgBox("Unchecking this will delete the information in the adjacent text field. " & _
            Chr(13) & Chr(13) & "Continue?", vbYesNo + vbDefaultButton2) = vbYes Then
                                                ' If the user clicks 'Yes'
                Me.txtOther = Null            ' delete the data in txtOther            Else                                ' Otherwise, if the user doesn't click 'Yes'
                Cancel = True                   ' don't go through with the change (i.e., cancel the update),
                Me.chkOther.Undo                      ' restore the value of chkOther to the original answer (i.e., checked)
                Exit Sub                        ' and leave this routine
            End If
        End If
    End If
    
    'Check the final value in chkOther to determine whether to enable or disable txtOther.
    'If chkOther is True (i.e., checked), set txtOther's enabled property to True (i.e., -1).
    'If chkOther <> True (i.e., it's unchecked), set txtOther's enabled property to False (i.e., 0).
    Me.txtOther.Enabled = IIf(Me.chkOther = True, -1, 0)
     
End Sub

Revision: 13315
at April 19, 2009 12:09 by heislekw


Initial Code
Private Sub q6g_AfterUpdate()

    ' Validation for check box with specify field
   
    If Not IsNull(Me.q6_specify) Then           
        If Not Me.q6g.Value = True Or IsNull(Me.q6g) Then 
            If MsgBox("Unchecking this will delete the information in the adjacent text field. " & _
            Chr(13) & Chr(13) & "Continue?", vbYesNo + vbDefaultButton2) = vbYes Then
                Me.q6_specify = Null            
            Else                                
                Cancel = True                   
                Me.q6g.Undo                     
                Exit Sub                        
            End If
        End If
    End If
    
    Me.q6_specify.Enabled = IIf(Me.q6g = True, -1, 0)
        
End Sub

Initial URL


Initial Description


Initial Title
Validation for a check box with a corresponding text field

Initial Tags
validation

Initial Language
Visual Basic