Date Function manipulate result

J

Jen

Help to manipulate/assign result CalculateAge to my ActiveDocument screen,
assign it toa DocProp or DocVariable
and a ContentControl
or the ActiveDocument screen at a bookmark please?
I can read result CalculateAge in a MsgBox fine.


Function Calculate(birthDate As Date) As Byte
Dim birthdayNotPassed As Boolean
birthdayNotPassed = CDate(Month(birthDate) & " / " & _
Day(birthDate) & " / " & _
Year(Now)) > Now
CalculateAge = Year(Now) - Year(birthDate) + birthdayNotPassed

End Function
 
H

Helmut Weber

Hi Jen,

use "option explicit",
as CalculateAge is not declared in your code.

Maybe this helps:

Function Calculate(birthDate As Date) As String
Dim birthdayNotPassed As Boolean
birthdayNotPassed = CDate(Month(birthDate) & " / " & _
Day(birthDate) & " / " & _
Year(Now)) > Now
Calculate = CStr(Year(Now) - Year(birthDate) + birthdayNotPassed)
End Function

Sub Test561()
ActiveDocument.Variables("Age").Value = _
Calculate("06.11.49") ' watch out, german date format
MsgBox ActiveDocument.Variables("Age").Value
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
J

Jen

Thanks once again Helmut, I have Option Explicit. I was having trouble with
accessing the answer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top