if null .Visible = True - not working!

XelaIrodavlas

Registered User.
Local time
Today, 21:37
Joined
Oct 26, 2012
Messages
175
[Solved] if null .Visible = True - not working!

Hi all,

I have what would seem to be a simple issue, but I can't figure out why this isn't working...

I have a form named [Assets] which contains two command buttons named [Retire] and [UnRetire], these buttons simply add or remove today's date to the control field [RetiredDate], which basically serves to deactivate the asset in other queries.

My challenge is I only want one of the buttons to be visible at a time, depending on whether the [RetiredDate] field is null or contains a value. so i came up with this code to check on the OnCurrent event:

Code:
Private Sub Form_Current()

If Me!RetiredDate = Null Then

 Me!Retire.Visible = True
 Me!UnRetire.Visible = False
 Else
 Me!Retire.Visible = False
 Me!UnRetire.Visible = True

End If

Far as I can tell this should work fine, but all records are showing the same result ([UnRetire] visible, [Retire] not visible) suggesting the [RetiredDate] is not null for any records. But I have checked and [RetiredDate] is definately Null for some of the entries, so why isn't the code picking up on that? Maybe I am missing something obvious...?

Any ideas greatly appreciated,

thanks in advance,

Alex S

[edit]: BTW i have tried editing the If part to: If Me!RetiredDate = Null Or Me!RetiredDate = "" But that hasn't helped either :(
 
Last edited:
Null is not something you can compare using arithmetic operation. You need to either use IsDate or IsNull funcitons or Len. something like
Code:
Private Sub Form_Current()
    If Len(Me!RetiredDate & vbNullString) = 0 Then
        Me!Retire.Visible = True
        Me!UnRetire.Visible = False
    Else
        Me!Retire.Visible = False
        Me!UnRetire.Visible = True
    End If
End Sub
 
Ruddy marvelous, can't believe this hasn't come up before.

Thanks for the help as always :)
 

Users who are viewing this thread

Back
Top Bottom