By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,826 Members | 2,443 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,826 IT Pros & Developers. It's quick & easy.

Need help with clearing an error message" Invalid Null usage" in Access

P: 1
"Hi there,

I am having a bit of a headache trying to get the following coding to work. What I am trying to accomplish is turn around totals between and open date and resolution date. My coding works fine if the fields are filled in, but how do I get the blank data set to zero so that I am not getting and error message?

Will using the Nz function eliminate this problem?

See Below....

This is the field from my query...
TimeElapsed: GetElapsedDays([ResolutionDate]-[OpenDate])

Field from Time elaspe function:

Function GetElapsedDays(interval)
Dim days As Long

days = Int(CSng(interval))
GetElapsedDays = days & " days "

End Function

Any suggestions will be greatly appreciated :)"
Mar 1 '07 #1
Share this Question
Share on Google+
1 Reply


ADezii
Expert 5K+
P: 8,636
"Hi there,

I am having a bit of a headache trying to get the following coding to work. What I am trying to accomplish is turn around totals between and open date and resolution date. My coding works fine if the fields are filled in, but how do I get the blank data set to zero so that I am not getting and error message?

Will using the Nz function eliminate this problem?

See Below....

This is the field from my query...
TimeElapsed: GetElapsedDays([ResolutionDate]-[OpenDate])

Field from Time elaspe function:

Function GetElapsedDays(interval)
Dim days As Long

days = Int(CSng(interval))
GetElapsedDays = days & " days "

End Function

Any suggestions will be greatly appreciated :)"
The following code will work unless:
__1 You declare interval as any other Data Type other than Variant as in:
Public Function GetElapsedDays(interval As Long)
__2 You do not assign any Data Type other than Variant or String to the return value of the Function as in: Public Function GetElapsedDays(interval) As Long
__3 1 and 2 will not work under either condition. Just use the code below as it is and you'll be OK.
Expand|Select|Wrap|Line Numbers
  1. Public Function GetElapsedDays(interval)
  2. Dim days As Long
  3.  
  4. If IsNull(interval) Then
  5.   GetElapsedDays = "N/A"
  6. Else
  7.   days = Int(CSng(interval))
  8.   GetElapsedDays = days & " days "
  9. End If
  10. End Function
Mar 1 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.