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

Datediff and calculating the warranty

Status
Not open for further replies.

Lightlancer

Programmer
Jul 18, 2008
88
NL
Hi there,

Im trying to calculate the warranty,
in a form, (onload event) it must check if the warranty is still on,
Datediff must calculate the differce between [aanschafdatum] + 12 Months

if the buy date is more then 12 months ago, the checkbox must be False,

When its in the 12 months, it must be True
I tried the following code must it doesnt seem to work:

Code:
If DateDiff("m", Now(), [aanschafdatum]) > [Garantietijd] = True Then
Me.Garantie = False
Else
Me.Garantie = True
this code must tell: if the date between now and [aanschafdatum] is more then ?? Months (wich is stated in [Garantietijd] mostly its 12) Then, Me.Garantie = False
Otherwise its true offcourse,

But, the checkbox stays always on true,......

Any ideas??
 
Switch it around

If DateDiff("m", [aanschafdatum],Now()) > [Garantietijd] = True Then
Me.Garantie = False
Else
Me.Garantie = True
 
Thanks for the quick reaction, but it also doesnt work, it stays on True

(i also tried if the checkbox was ok and bounded allright but thats find, when i put :

Code:
Else
me.checkbox = False

the checkbox goes false......

 
what happands when you change the name of the check box to Garantie
 
How are ya Lightlancer . . .

. . . and this (Garantietijd is not needed!):
Code:
[blue]   If DateAdd("m", -12, Date) > Me!aanschafdatum Then
      Me!Garantie = False
   Else
      Me!Garantie = True
   End If[/blue]

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thanks for the reactions,

going to try to change it to Garantie
also, TheAceMan, as i told above, the warranty can be different, 12 months, 24 months etc etc..... so thats different.

 
Lightlancer . . .

No problem. You can make a routine out if it and pass the warrenty period. In the code module of the form the routine would look like:
Code:
[blue]Public Sub SetGarantie(GtyPeriod As Integer)
   
   If DateAdd("m", [purple][b]-1 * GtyPeriod[/b][/purple], Date) > Me!aanschafdatum Then
      Me!Garantie = False
   Else
      Me!Garantie = True
   End If

End Sub[/blue]
Assuming you have a field holding the Warranty Period, a call to the routine would look like:
Code:
[blue]   Call SetGarantie(Me!Garranty)[/blue]

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
a little stupid question, where do i need to put the call???

in a callback function???
i will tried that first
 
The call statement goes in the OnCurrent event of the form as that's when it gets refreshed dates and needs to re-assess. Possibly also anywhere that you adjust the date of sale.

A callback function is something entirely different, don't confuse yourself by searching for help on those just yet...

JB
 
Lightlancer:

If you want to go with the Dateadd method no need to create a Sub or function

you can use this code

Code:
 If DateAdd("m", -Garantietijd, Date) > Me!aanschafdatum Then
      Me!Garantie = False
   Else
      Me!Garantie = True
   End If


As to where to put this code
The same place that you would put your orignal code
Code:
If DateDiff("m", Now(), [aanschafdatum]) > [Garantietijd] = True Then
Me.Garantie = False
Else
Me.Garantie = True

you mentioned that you put it in the on load event

If you need it to change for each record put it in the on current event

if you really want to put it all in one line put this in the on current event

Code:
Me.Garantie = not (DateDiff("m", [aanschafdatum],Now()) > [Garantietijd])
 
if i use this code from theaceman,
Code:
   If DateAdd("m", -1 * GtyPeriod, Now()) > (Me!aanschafdatum) Then
      Me.Garantie = False
   Else
      Me.Garantie = True
      
   End If
the access tells me error
fout -2147352567 (80020009) tijdens uitvoering:

U kunt geen waarde aan dit object toekennen.
(translated: Error -2147352567 (80020009) during this event:
you cannot give this object any value)

Any idea's......

the code stops at me.garantie = true or me.garantie = false
but when i set me.garantie = true before this code , the checkbox goes True and it still give this error at the same point in this code......
 
YEAHH,,
finally, i solved this error by putting
Code:
Call SetGarantie(Me!Garranty)
to Onload event and removed it from the onOpen event..
Now it works fine,

Thanks everybody for all the tips and tricks.....

Greetz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top