Here is a Pretty quick piece of code I crufted up....
' /* Declare Our Variables */
Dim d1
Dim d2
Dim RetUnit
Dim Diff
' /* Try To Get The Starting Date */
d1 = InputBox("Please Enter The Starting Date")
If d1 = "" Then Exit Sub
' /* Try To Get The Ending Date */
d2 = InputBox("Please Enter The Ending Date")
If d2 = "" Then Exit Sub
' /* Try To Get The Interval Unit To Return (Days Off, Weeks Off, etc) */
RetUnit = InputBox("Day, Week, Month, or Year?")
If RetUnit = "" Then
Exit Sub
Else
' /* Set The Interval Code Based On The Users Selection */
If lcase(RetUnit) = "day" Then
RetUnit = "d"
ElseIf lcase(RetUnit) = "week" Then
RetUnit = "ww"
ElseIf lcase(RetUnit) = "month" Then
RetUnit = "m"
Else
RetUnit = "yyyy"
End If
End If
' /* Calculate The Difference Between Date1, and Date2, With The Chosen Interval */
Diff = DateDiff(RetUnit, d1, d2)
' /* Show The User */
MsgBox "The Difference Is " & Diff Naturally, I would imagine that you are going to want to change things so that it's a little more friendly to you, I'm not sure.... but the magic behind how it works is the "DateDiff" function. The DateDiff function calculates the difference between 2 dates, but it has to know what interval it should use..... do you want to know how many months, days, years, etc? So, that's the first piece of info you have to give datediff. In The Example above, we use a variable (RetUnit) that will contain that information based on what you type in the last popup box. So, if you want it in Days, it will automatically use DateDiff with "d" as the first parameter. If you know that you will only ever use this with Days, Then you could simply change the Line
Diff = DateDiff(RetUnit, d1, d2) to read
Diff = DateDiff("d", d1, d2) and it will return the value in Days Only (Always). Here Is A Complete List Of Those Interval Codes:
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second
Also, another little Gem that I'd thought I'd throw into the mix here, is that the DateDiff function can be used in a Query.... Uh Oh. I don't do much with Queries, and you may have to modify for a different version of access or whatever (not sure), but I googled around and found the image attached below. I'm not sure if it would be easier for you to use the code in a macro or module, or just modify your Query to look something like the attachment, but either way, let me know how it turns out.