Hide Field if Another Field is Null

andysgirl8800

Registered User.
Local time
Today, 13:18
Joined
Mar 28, 2005
Messages
166
I'm sure this one is easy, but I can't seem to get the code to work right. I have a field called "Discharged" and "ProposedDischargeDate". What I want to do is if the "Discharged" field is empty, or null, I want the "ProposedDischargeDate" to be visible. Otherwise, I want it to remain hidden. I want this on either the AfterUpdate or the OnExit event of the "Discharged" field. Here's what I've tried:

If [Discharged].Value = "" Then
[ProposedDischargeDate].Visible = False
End If


or

' if the field is empty, show the proposed discharge date field
If Me.Discharged = null then Me.ProposedDischargeDate.visible = true
' if the field is not empty, hide the diagnosis field
If Me.Discharged = true then Me.ProposedDischargedDate.visible = false


But this doesn't seem to work. What am I doing wrong? Thanks for any help.
 
Hello:
The below code works:
Private Sub txtDischarged_AfterUpdate()
If IsNull(txtDischarged) Then txtProposedDischargedDate.Visible = False
If Not (IsNull(txtDischarged)) Then txtProposedDischargedDate.Visible = True

End Sub
'
You will need to put this in the FormCurrent event also.
Regards
Mark
 
The problem may acutally be the default value of discharged. The problem is that NULL,"",and 0 are NOT the same. If discharged is a date field you will need to make sure that the default value is NULL. "" represents and empty string value and is not equivalent to NULL. If discharged is a date value I would suspect that "" will not work.

You may want to try: if isnull([discharged].value] then [proposeddischargeddate].visible = false
 
ortaias said:
You may want to try: if isnull([discharged].value] then [proposeddischargeddate].visible = false

Where would I put this code? in the FormCurrent? or the field AfterUpdate?
 
andysgirl8800 said:
Where would I put this code? in the FormCurrent? or the field AfterUpdate?

If I'm reading what your wanting to accomplish, then I would say that you need to put the code in both locations.

HTH,
Shane
 

Users who are viewing this thread

Back
Top Bottom