Access VBA Error

By omnknt232006 ·
Hello, I am encountering an error whenver I try to run the datediff function in an access report. Its in the detail on format event. Can you not run this function during this event? The error I'm getting is Run-Time Error 5: Invalid Procedure call or argument.

Here's my code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim intAssetLife As Double
Dim POD As Date
Dim FYEnd As Date
Dim txtFYEnd As String

POD = Me.AcquisitionDate.Value
txtFYEnd = Me.FYEndDate.Value
FYEnd = CDate(txtFYEnd)
'Debug.Print FYEnd
Me.txtAssetAge.Value = DateDiff(yyyy, POD, FYEnd)
End Sub

Thanks for any help someone can provide.

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

Field values

by unhappyuser In reply to Access VBA Error

I don't use datediff but is that the correct format? Should you have quotes in there somewhere? Just wondering.

Are all the fields set to date? I'm thinking that you might be comparing apples to oranges. I sometimes will try compare a number to text and it screams at me.


Collapse -


by omnknt232006 In reply to Field values

The datediff formula is:
[Expression] = Datediff(interval as string, date 1 As Date, date 2 As Date) the string valuu is m for months, yyyy for year, d for day, ww for week etc. I have my variables defined but am wondering if I should put the interval in its own variable rather than just typing it in the first part of the formula. I'm gonna give that a shot, I'll report back.

Related Discussions

Related Forums