Question Locked

Access VBA Error

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

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.

3 replies

by unhappyuser

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.

EMD

by omnknt232006

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.

This discussion is closed to new replies.