Datediff. Its doing my head in! (1 Viewer)

Greyowlsl

Mlak Mlak
Local time
Today, 21:36
Joined
Oct 4, 2006
Messages
206
Hi guys,

I'm trying to use a very basic datediff function to show the number of years difference between the current date and the date in a text box.

I have look on many forums and tried so many different things.

I am a beginner coder, but I have no idea whats going on.

Here is the last bit of code it tried before i gave up. :banghead:

Code:
Private Sub Command209_Click()
Dim years As Long
Me.Text176.SetFocus
years = DateDiff("yyy", now, Text176.Value.DATE)
Me.Text207 = years
End Sub

I appreciate any help.

Thanks guys,
Leon
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 21:36
Joined
Jan 20, 2009
Messages
12,858
Code:
years = DateDiff("yyy[B]y[/B]", now, Me.Text176)
However you could simply put this in the ControlSource of Text207

Code:
= DateDiff("yyy[B]y[/B]", Now(), Text176)

BTW SetFocus is not required.
 

Greyowlsl

Mlak Mlak
Local time
Today, 21:36
Joined
Oct 4, 2006
Messages
206
Works, thanks!

The first piece of code is what originally tried. However I noticed you put "yyyy" instead of "yyy", I'm suspecting this was the problem all along :banghead:

,Leon
 

Users who are viewing this thread

Top Bottom