If not executing

  • Thread starter Thread starter CJ
  • Start date Start date
C

CJ

Hi Groupies:

I would like my form to check the warranty status of my equipment. If the
warranty expiry date is less than today and the warranty field is still
checked, I would like the warranty field to uncheck and a message box to pop
up.

I have the following code in the OnCurrent event of my form:

Dim MyDate
MyDate = Date

If (Me.dtmWarrantyExpiry < MyDate) And (Me.ysnWarranty = True) Then
Me.ysnWarranty = False
MsgBox "Warranty has expired for this item", vbOKOnly, "No Warranty"
Me.SKU_Number.SetFocus
End If

Although I do not get any error messages, nothing happens at all between
records.

Any ideas?
 
It is probably around the =True section of your If statement.

When I run into these problems I do something like this on the OnCurrent Event
MsgBox Me.dtmWarrantyExpiry
MsgBox Me.ysnWarranty
MsgBox MyDate

This will tell you exactly what Access sees as a value and you can adjust
your statement to reflect the correct values (if they are not already
correct).

Try that and write back.

PJ
 
Hi PJ

OK, so now my code is:

Private Sub Form_Current()

Dim MyDate
MyDate = Date

MsgBox Me.dtmWarrantyExpiry
MsgBox Me.ysnWarranty
MsgBox MyDate

If (Me.dtmWarrantyExpiry < MyDate) And (Me.ysnWarranty = -1) Then
Me.ysnWarranty = 0
MsgBox "Warranty has expired for this item", vbOKOnly, "TOG Systems"
Me.SKU_Number.SetFocus
End If

End Sub

The values in the message boxes are what I expect to see:

Warranty Expiry: May 29 2007
Warranty -1
My Date: May 30 2008

So, the warranty expired last year, the warranty check box needs to change
to 0 and the message box needs to show up.
 
Fixed it!

dtmWarrantyExpiry is a calculated field that returns a date. It's one of
those instances where you need to perform the calculation in order for the
comparison to work. So, my code is:

Dim MyDate
MyDate = Date

If (Me.Date_Purchased + Me.sngWarrantyDuration) And (Me.ysnWarranty = -1)
Then
Me.ysnWarranty = 0
MsgBox "Warranty has expired for this item", vbOKOnly, "TOG Systems"
Me.SKU_Number.SetFocus
End If

Thanks for steering me in the right direction!

CJ
 
Sorry, there was an error in the code I posted.

It should have been :

Dim MyDate
MyDate = Date

If (Me.Date_Purchased + Me.sngWarrantyDuration) < MyDate And (Me.ysnWarranty
= -1) Then
Me.ysnWarranty = 0
MsgBox "Warranty has expired for this item", vbOKOnly, "TOG Systems"
Me.SKU_Number.SetFocus
End If


CJ

CJ said:
Fixed it!

dtmWarrantyExpiry is a calculated field that returns a date. It's one of
those instances where you need to perform the calculation in order for the
comparison to work. So, my code is:

Dim MyDate
MyDate = Date

If (Me.Date_Purchased + Me.sngWarrantyDuration) And (Me.ysnWarranty = -1)
Then
Me.ysnWarranty = 0
MsgBox "Warranty has expired for this item", vbOKOnly, "TOG Systems"
Me.SKU_Number.SetFocus
End If

Thanks for steering me in the right direction!

CJ
 
Back
Top