Null Problem

Bruce75

Psychologist
Local time
Today, 09:01
Joined
Sep 29, 2004
Messages
46
Hello

I have a bit of a problem. I have a table with three fields: referraldate (date formate), dischargeddate (date format) and discharged (checkbox). I am trying to write some code in the OnChange event of the dischargeddate. I want to get it so that if a discharge date is present the discharged checkbox is ticked, and if no discharge date is present, there is no tick.

I have got this so far:

Private Sub dischargeddate_Change()

If dischargeddate = "" Then
Me.discharged = 0
Else
Me.discharged = 1
End If
End Sub

when a discharge date is added, the checkbox is ticked, however, when I remove a date, the checkbox doesn't untick. I realise that when you delete a date this is different that having a null value for that field, hence I tried "".

Please can anyone point out what I am doing wrong?

many thanks

Bruce
 
Use the Discharge Date's AFTER UPDATE event for this:
Code:
If Me.dischargeddate = "" Then
   Me.discharged = False
Else
   Me.discharged = True
End If
 
thanks Bob, but the same problem occurs. Adding a discharged date checks the check box, but deleting a discharged date does not uncheck the checkbox. Any ideas?

cheers
 
My Bad -

Code:
If IsNull(Me.dischargeddate) Or Me.dischargeddate = "" Then
   Me.discharged = False
Else
   Me.discharged = True
End If

but if it is bound to a date/time field then you can't have empty strings on a date field. It either has a value or is null so you wouldn't need the Me.dischargeddate = "" part in there.
 
thanks yet again Bob

You are clearly some kind of King of Access
 

Users who are viewing this thread

Back
Top Bottom