Am designing an application in Access 2007 and cannot seem to get VB code to update field. Am using a tab form to enter payments and need to have the paid through date calculated automatically and entered into the paid through field in the Subscriber table. Below is the code for the after update event. Help is much appreciated..And if there is another way to accomplish this, suggestions are shamelessly accepted...
Private Sub Form_AfterUpdate()
' Update other forms if they are open.
If IsOpen("Subscribers") Then
' Refresh the Subscribers form to show
' the PaidThrough value.
Forms!Subscribers.Refresh
End If
If IsOpen("PaymentHistory") Then
' Requery the PaymentHistory pop-up form
' to show the new payment.
Forms!PaymentHistory.Requery
End If
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
' Check to make sure a payment method is selected, then update
' the PaidThrough field (in the Subscribers table)
Dim bytMonths As Byte
If PaymentType = 0 Then
DisplayMessage "You must select a payment Type."
Cancel = True
Exit Sub
End If
bytMonths = YearsPaid * 12
Select Case PaymentType
Case 22, 23, 24, 25, 26
If IsNull(PaidThrough) Or PaidThrough < Date Then
' If this is the first payment, set PaidThrough from current date.
PaidThrough = DateSerial(Year(Date), Month(Date) + bytMonths, 1)
PaymentType = PaymentType
Else
' Otherwise, add additional months to the PaidThrough value.
PaidThrough = DateSerial(Year(PaidThrough), Month(PaidThrough) + _
bytMonths, 1)
PaymentType = PaymentType
End If
Case 27, 28, 29
Exit Sub
Case Else
End Select
Exit Sub
End Sub
Private Sub Form_AfterUpdate()
' Update other forms if they are open.
If IsOpen("Subscribers") Then
' Refresh the Subscribers form to show
' the PaidThrough value.
Forms!Subscribers.Refresh
End If
If IsOpen("PaymentHistory") Then
' Requery the PaymentHistory pop-up form
' to show the new payment.
Forms!PaymentHistory.Requery
End If
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
' Check to make sure a payment method is selected, then update
' the PaidThrough field (in the Subscribers table)
Dim bytMonths As Byte
If PaymentType = 0 Then
DisplayMessage "You must select a payment Type."
Cancel = True
Exit Sub
End If
bytMonths = YearsPaid * 12
Select Case PaymentType
Case 22, 23, 24, 25, 26
If IsNull(PaidThrough) Or PaidThrough < Date Then
' If this is the first payment, set PaidThrough from current date.
PaidThrough = DateSerial(Year(Date), Month(Date) + bytMonths, 1)
PaymentType = PaymentType
Else
' Otherwise, add additional months to the PaidThrough value.
PaidThrough = DateSerial(Year(PaidThrough), Month(PaidThrough) + _
bytMonths, 1)
PaymentType = PaymentType
End If
Case 27, 28, 29
Exit Sub
Case Else
End Select
Exit Sub
End Sub