Code Doesn't Work

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If PayCycle = Weekly Then
Return PaymentDate + 7

ElseIf PayCycle = Bi - Weekly Then
Return PaymentDate + 14

ElseIf PayCycle = Monthly Then
Return PaymentDate + 30

End If
End Sub
 
Waht is happening? An error? What results do you get? What is "PayCycle"?
Is it a text field? Have you tried using DateAdd?

Please post as though you are talking to someone who is not sitting at your
desk using your database.
 
Well, you can't add dates to a text field. What does "a" plus 3 days equal?
Access does not know how to do so. You need to use a date field.

If the field always contains data that looks like a date, there are built-in
functions you can use to make Access convert it to a date.
 
Look up "datevalue" in help for more information on turning text into a date
for the purpose of performing date math on it.
 
DeeDee said:
If PayCycle = Weekly Then
Return PaymentDate + 7

ElseIf PayCycle = Bi - Weekly Then
Return PaymentDate + 14

ElseIf PayCycle = Monthly Then
Return PaymentDate + 30

End If
End Sub

Is this code in a function? If so, you need to assign the return value
to the name of the function, as well as changing your code in other
ways. There is no "Return" statement in VBA.

You *could* have a function something like this:

'----- start of example code -----
Function NextPaymentDate( _
PaymentDate As Date, _
PayCycle As String) _
As Date

Select Case PayCycle

Case "Weekly"
NextPaymentDate = PaymentDate + 7


Case "Bi - Weekly"
NextPaymentDate = PaymentDate + 14


Case "Monthly"
NextPaymentDate = DateAdd("m", 1, PaymentDate)

Case Else
Err.Raise 5 ' bad value for PayCycle

End Select

End Function
'----- end of example code -----

But you haven't told us anything about where your code was placed, or
how it is to be called, so all this is just speculation.
 
Back
Top