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

Auto Update Field

Status
Not open for further replies.

bdm1

Programmer
Feb 4, 2002
75
0
0
US
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
 
Not quite sure what you need are you just trying to get the date to advance to the next month after payment?
 
If so it would look somthing like this:


If IsNull(PaidThrough) Or PaidThrough < Date Then
' If this is the first payment, set PaidThrough from current date.
PaidThrough = Me.DateSerial= DateAdd("m", 1, PaidThrough)
PaymentType = PaymentType
 
sorry:

If IsNull(PaidThrough) Or PaidThrough < Date Then ' If this is the first payment, set PaidThrough from current date. PaidThrough = DateAdd("m", 1, PaidThrough) PaymentType = PaymentType
 
God this not my day, below is what it should look like if your trying to advance the date.

If IsNull(PaidThrough) Or PaidThrough < Date Then
' If this is the first payment, set PaidThrough from current date.
PaidThrough = DateAdd("m", 1, PaidThrough)
PaymentType = PaymentType
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top