Code Doesn't Work

D

DeeDee

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
 
R

Rick B

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.
 
R

Rick B

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.
 
R

Rick B

Look up "datevalue" in help for more information on turning text into a date
for the purpose of performing date math on it.
 
D

Dirk Goldgar

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top