You are here:

Using MS Access/Format Field for Yrs/Mths

Advertisement


Question
QUESTION: Hi Scott,

Instead of having a field displaying 58.5 years, can I apply a format in the field's properties so it displays as 58y, 6mths?

Searched all day without success :)

thanks in anticipation
Pete

ANSWER: Not a format. You would have to use a function to convert the numbers to text. Are you calculating the value or just entering it?

Hope this helps,
Scott<>
Blog: http://scottgem.wordpress.com
Website: http://www.diamondassoc.com
Microsoft Access MVP 2007
Author: Microsoft Office Access 2007 VBA

---------- FOLLOW-UP ----------

QUESTION: Hi Scott

It's a calculated field, i.e. datediff between date of birth and today, and the answer comes out as a whole number plus decimal point.   If I reduce the decimal point to zero, it rounds up (grrr! haha)

Are you able to help with the syntax for the formatting using a function?

cheers
Pete

Answer

Public Function YrsMths(dblDiff As Double) As String

Dim intYrs As integer, intMths As Integer

intYrs = Int(dblDiff)
intMths = (dblDiff-intYrs)*12

YrsMths= intYrs & " Years " & intMths & " Months"

End Function

Something like that.

Hope this helps,
Scott<>
Blog: http://scottgem.wordpress.com
Website: http://www.diamondassoc.com
Microsoft Access MVP 2007
Author: Microsoft Office Access 2007 VBA

Using MS Access

All Answers


Answers by Expert:


Ask Experts

Volunteer


Scottgem

Expertise

I can answer almost all types of questions relating to Microsoft Access usage and application design. My strengths are database and interface design.

Experience

I've been designing databases for over 25 years working with dBase, FoxPro, Approach and Access.

Organizations
Author of Microsoft Office Access 2007 VBA
Techncial Editor for Special Edition Using Microsoft Access 2007 and Access 2007 Forms, Reports & Queries From Que Publishing

Education/Credentials
Brooklyn College BA

©2016 About.com. All rights reserved.