IF statement problem

Danny_H

Registered User.
Local time
Today, 22:35
Joined
Feb 14, 2013
Messages
15
Hi

I am trying to get a txt box to state Yes after a date has been entered into another box

for some reason the IF statement is not working?

Code below:

Private Sub Final_approval_date_AfterUpdate()

If Me.Final_approval_date.Value = True Then Me.Status.Value = "Closed"
Me.Refresh

End Sub

I think it could be because I am asking if Final_approval_date is true and not an actual figure as it works fine for text or numbers

Help is much appreciated

Thanks
 
I think it could be because I am asking if Final_approval_date is true and not an actual figure
Yes that is correct.. Try the following.. It should help..
Code:
Private Sub Final_approval_date_AfterUpdate()
    If [URL="http://www.techonthenet.com/access/functions/advanced/isdate.php"]IsDate[/URL](Me.Final_approval_date) Then Me.Status.Value = "Closed"
    Me.Refresh
End Sub
 
forget the "value" qualifier, everywhere. it's either the default, or may even be wrong

you also do not need the refresh

simply this


Code:
If nz(Final_approval_date,0)< >0 Then 
     Status = "Closed"
else
     status = ""
end if

the problem arose because you are testing whether a date (ie a number) is "true", rather than whether the date is a real date.

in vba true is a special value of -1. since the date is not -1, your test returns false.

the example I gave returns true for any date other than a date of zero (which is a date in 1899), and uses nz to get around the additional coding problem of a blank (null) date.

note that you need to handle BOTH the date set , and the date blank cases - otherwise your status will set to CLOSED on the first occasion, and will then remain CLOSED when it is not closed.
 
Last edited:
lol, sorry

Tried both ways and both ways worked for me.

Chose Pr2's way as it is just more in line with what I needed

Thanks again
 

Users who are viewing this thread

Back
Top Bottom