Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with isDate

Status
Not open for further replies.

SW2004

Technical User
Jul 13, 2004
24
GB
Hi,

I have a VB app that sets an account expiry date for Active Directory accounts however if I don't specify an expiry date then the account is set to expire on 28th Dec 1899! (I believe this is a cdate or isDate issue). I've narrowed the fault down to the code below, if the code below is excluded from the program the account expiry date is set to 'Never' as I would expect. Please take a look and if you can help I'd love to here from you.

Thanks

If Not (Trim(newUser.DateExpires) = "") Then
If (IsDate(newUser.DateExpires)) Then
objNewUser.AccountExpirationDate = newUser.DateExpires
objNewUser.SetInfo
If (Err.Number <> 0) Then
doMsg ("Could not set the account expiration date for user " & newUser.SAMAccountName & ". Error : " & Err.Description)
Err.Clear
End If
End If
End If
 
Interesting - particularly since an unset date should actually come out as 31 Dec 1899 ...

However, you are basically correct: if newUser.DateExpires holds a string that cannot be parsed as a date (which is impressive, as IsDate is pretty good ...), then none of the code inside the If statement will run. Have you actually put a break point on

If (IsDate(newUser.DateExpires)) Then

to see what newUser.DateExpires actually contains?
 
I'll try what you suggest later today, thanks for that.

Steven
 


Make sure you use IsDate() prior to any date conversion functions, like CDate(), on string variables, or prior to actually sticking a string date into a date variable.

Otherwise, what may happen is this:

DateExpires = -2
DateExpires = CDate(DateExpires)

debug.? IsDate(DateExpires)
= True = 28 Dec 1899

(btw: 30 Dec 1899 would be an "unset" date)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top