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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datediff question

Status
Not open for further replies.

clientuser

Programmer
Apr 18, 2001
296
0
0
US
I have code that is suppose to tell if a certain amount of days have passed, if the days in question (in this case 90 days) have passed after running a query the form would show a label letting the user know its ok to call the client.. if not then the label simply says not enough time has passed..

Here is the code I am using..
------------------------------------------------------------
Private Sub Form_Load()
Dim HoldDate As String

HoldDate = DateDiff("d", [Date/Time], Date)

MsgBox HoldDate 'just for debuggin at the moment

If HoldDate > 90 Then
Label11.Visible = True

Else

If HoldDate < 90 And Not 0 Then

Label11.Visible = True
Label11.Caption = &quot;---> Not enough time as passed <---&quot;
[Client ID or name].Enabled = False
[Date/Time].Enabled = False

End If
End If


the problem is, if the results from the datediff are 0 it still runs the code below the if statement..

any suggestions?
 
hi,

the problem is in your second if statement it works as
If (HoldDate < 90) And (Not 0) Then when what you probably want is
If HoldDate < 90 And HoldDate <> 0 Then

HTH

Andy
 
sorry,additional - i also meant to post that Not 0 is always true, so it is only checking if it is < 90
 
Alright, I have to say it. I STRONGLY suggest that you rename your fields and not use reserved words. Your field called [Date/Time] could very easily cause you problems in the future if you forget to put the square brackets around it. You would end up with todays date divided by the current time.

Also, I see you declared HoldDate as a string. It might be better to make this a number. Terry M. Hoey
 
yeah terry i know all that.. i would go through and clean up this database that was given to me, but that would take a lot of time cause it has a lot of mistakes in it..

so for now i just use it as is and work with it..


 
Even better - declare HoldDate as a darn DATE! Also check into the format and CDate functions to make sure you're comparing apples to apples...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top