if date field not null or >0 check check box

  • Thread starter Thread starter JK
  • Start date Start date
J

JK

If a user enters a date in a date field, check a check box. For some reason I
cannot make this work. I have every other variation working except this one.
If a user checks the "Inactive" check box, today's date is automatically
inserted into the "DateFinished" field. If a user unchecks the check box, the
"DateFinished" field is cleared. If there is a date in the "DateFinished"
field and the check box is checked and a user clears the date in the
"DateFinished" field the check box is automatically unchecked. However, like
I said, if there is no date in the "DateFinished" field and the check box is
unchecked and a user enters a date in the "DateFinished" field I cannot make
the check box automatically check for some reason. Any help would be
appreciated.

Private Sub DateFinished_AfterUpdate()
If IsNull(Me.DateFinished Or Me.DateFinished = "") Then
Me.ckInactive = False
Else
If Not IsNull(Me.DateFinished Or Me.DateFinished > 0) Then
Me.ckInactive = True
End If
End If
End Sub

Private Sub ckInactive_AfterUpdate()
If (Me.ckInactive = True) Then
Me.DateFinished = Now()
Else
If (Me.ckInactive = False) Then
Me.DateFinished = ""
End If
End If
End Sub

Regards,
Jason
 
Your syntax is incorrect for IsNull.

Try

Private Sub DateFinished_AfterUpdate()
If IsNull(Me.DateFinished) Or Me.DateFinished = "" Then
Me.ckInactive = False
Else
Me.ckInactive = True
End If
End Sub

(I don't see any need for the second If statement)

You could also try either

Private Sub DateFinished_AfterUpdate()
Me.ckInactive = (IsNull(Me.DateFinished) = False) And Me.DateFinished <>
""
End Sub

or

Private Sub DateFinished_AfterUpdate()
Me.ckInactive = Len(Me.DateFinished & "") >0
End Sub
 
HI JK,
try this
Private Sub DateFinished_AfterUpdate()

If IsNull(Me.DateFinished) Or Me.DateFinished = "" Then
Me.ckInactive = False
endif
If Not IsNull(Me.DateFinished) and Me.DateFinished<>"" Then
Me.ckInactive = True
End If

End Sub

HTH Paolo
 
I figured out what the problem is, but I don't know what the solution is. If
I manually enter the date, i.e. 1/28/09 and hit tab or enter - the check box
automatically checks. If I use my calendar command button or hit the letter T
(see code below) the check box does not check.

Any ideas? Thx so much for all your help.

Private Sub ApprovedDate_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 84, 116 'T
KeyAscii = 0
Screen.ActiveControl = Date

Case 89, 121 'Y
KeyAscii = 0
Screen.ActiveControl = Date - 1

Case 43 'Plus key
KeyAscii = 0
Screen.ActiveControl = Screen.ActiveControl + 1

Case 45 'Minus key
KeyAscii = 0
Screen.ActiveControl = Screen.ActiveControl - 1
End Select
End Sub
 
I wish my mind would think like a programmer. I figured it out; I added your
code to the command button and the other code I mentioned in my last email.
Thx for your help!

Private Sub cmdDateFin_Click()
Dim blRet As Boolean
Dim dtStart As Date, dtEnd As Date

dtStart = Nz(Me.DateFinished.Value, 0)
dtEnd = 0

blRet = ShowMonthCalendar(mc, dtStart, dtEnd)
If blRet = True Then
Me.DateFinished = dtStart
Me.ckInactive = Len(Me.DateFinished & "") > 0
Else
'Add any message here if you want to inform the user that no date was selected
Me.ckInactive = Len(Me.DateFinished & "") > 0
End If
End Sub


Private Sub DateFinished_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 84, 116 'T
KeyAscii = 0
Screen.ActiveControl = Date
Me.ckInactive = Len(Me.DateFinished & "") > 0

Case 89, 121 'Y
KeyAscii = 0
Screen.ActiveControl = Date - 1
Me.ckInactive = Len(Me.DateFinished & "") > 0

Case 43 'Plus key
KeyAscii = 0
Screen.ActiveControl = Screen.ActiveControl + 1

Case 45 'Minus key
KeyAscii = 0
Screen.ActiveControl = Screen.ActiveControl - 1
End Select
End Sub
 
Back
Top