Simple VBA question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello All

I'm sure this is going to be an easy one for virtually everyone... bar me of
course!

I want to code my form to subtract a future date from today's date to get an
integer value = number of days between these dates.

a = Format(Now, "dd/mm/yy")
b = futuredate

but

c = b - a 'always returns an error message

Can someone please help?!

Many thanks in advance and kind regards, Nick
 
How have you declared a, b and futuredate (i.e.: did you use a Dim statement
for them)? If you haven't declared them, they'll be created as Variants.
However, the fact that you're using the Format function in the first
assignment means that a will be treated as text.

Assuming that futuredate is properly assigned, all you need to calculate the
number of days between the dates is:

DateDiff("d", Date(), futuredate)
 
Nick said:
Hello All

I'm sure this is going to be an easy one for virtually everyone... bar me
of
course!

I want to code my form to subtract a future date from today's date to get
an
integer value = number of days between these dates.

a = Format(Now, "dd/mm/yy")
b = futuredate

but

c = b - a 'always returns an error message

Can someone please help?!

Many thanks in advance and kind regards, Nick

Take a look at the DateDiff function in help. Does exactly what you want.
 
Back
Top