Answer» Dear Sir
I have designed a program in VB 6.0 and have used Microsoft Access 2002 as database. In my database table there is a field named as “warranty void” where data is being saved as “purchase date+365” i.e. I have fixed warranty date 1 year. Please see my code in below. In that table there is another field named as “warranty” where it stores YES or NO i.e. YES is for warranty available and NO for non-availability.
Now I want that, when date in field “warranty void” WOULD be greater than CURRENT date, automatically “warranty EXPIRED” text would be displayed in “warranty” field.
For example, “purchase date” is 5/25/2009. Then from my above equation, data in “warranty void” field is being saved as “purchase date+365” which equals to 5/25/2010. On 5/26/2010, “warranty expired” text would be displayed in “warranty” field as it has already crossed 1 year and that’s what I want. To save data, I have used below coding and it is working well.
Private Sub cmdsave_Click() On Error Resume Next DBconnect If rst.State = adStateOpen Then rst.Close rst.Open "tblpurchasesupplyqty", cnt, adOpenDynamic, adLockOptimistic With rst .AddNew .Fields(0) = cmbitem.Text .Fields(1) = cmbbrand.Text .Fields(2) = cmbpurchaseqty.Text .Fields(3) = purchasedt.Value .Fields(4) = cmbpurchaseqty.Text .Fields(5) = cmbsuppliername.Text .Fields(6) = cmbitemrefno.Text .Fields(7) = cmbsupplierrefno.Text .Fields( = chkwarrenty.Value .Fields(9) = warrentyvoiddt.Value If chkwarrenty.Value = 1 And warrentyvoiddt.Value = Date Then MsgBox "WARRENTY Date can't be equal to current date", vbCritical, "Incorrect Warrenty Selection" Exit Sub ElseIf chkwarrenty.Value = 1 And warrentyvoiddt.Value < purchasedt.Value + CDate(365) Then MsgBox "PLEASE SELECT DATE UPTO 1 YEAR WARRENTY PERIOD", vbCritical, "INVALID WARRENTY PERIOD" ElseIf chkwarrenty.Value = 1 And warrentyvoiddt.Value >= purchasedt.Value + CDate(365) Then MsgBox "Data Saved Successfully....", vbInformation, "SAVED DIALOG BOX" .Update End If End With End Sub
Please help by providing the necessary solution.
Regards Pervez
|