PDA

View Full Version : Solved: Convert a formula from Excel to Access



winxmun
10-28-2008, 08:41 PM
Hi there,

Anyone know how to convert the following excel formula to be used in Access's visual basic?

=IF(((29/10/2008-01/05/2003)/365)<1,"1",(ROUNDDOWN(((29/10/2008-01/05/2003)/365),0)))

tks & regards
:yes

OBP
10-30-2008, 05:32 AM
I assume that you do not actually want to use 29/10/2008 and 01/05/2003, but field values in all records and place the result in another field?
the VBA to do so would be
if (date1 - date2)/365<1 then
field3 = 1
else
field3 = Round((date1 - date2)/365),0)
end if

However Access's Round does not actually Round Down, but up or down. So if you want to force a rounddown you need to manipulate the data a bit more instead. I wrote a KB article on how to Roundup, which I have now modified to show rounding down as well.

You can also do this in a Query as well of course.

winxmun
07-02-2009, 07:46 AM
Tks OBP...:thumb