Need vba function to fix dates in a field

I have a "date hired" field - text 10
in my "Employee" table.

folks are entering:
9/9/2004
1/02/1989

What I need:
I need the month and day to have a leading zero always:

Thanks
fordraiders
LVL 3
FordraidersAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kelvin SparksCommented:
Use the field's Before Update property and set it to be Me.Fieldname = Format(Me.Fieldname, "dd/mm/yyyy") - change the format string to suit your local requirements.


Kelvin
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ryan ChongCommented:
go to the textfield's Format property and format accordingly. We probably no need to use Format function in this case (if that field is bounded to the source that's a risk we may also changed its original value).

MS ACCESS 2003: DEFINE A CUSTOM FORMAT FOR A DATE/TIME FIELD ON A FORM
http://www.techonthenet.com/access/forms/format_date.php
0
FordraidersAuthor Commented:
I do not have a form. So I need to loop through the table and fix any dates that are not in the format I need.
0
FordraidersAuthor Commented:
this worked... based on  kelvin:
Public Sub FixDate()


Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT [Date Hired], [birthdate] FROM [Employees Information2]")

'Check to see if the recordset actually contains rows
If Not (rs.EOF And rs.BOF) Then
    rs.MoveFirst 'Unnecessary in this case, but still a good habit
    Do Until rs.EOF = True
        'Perform an edit
        rs.Edit
        rs![Date Hired] = Format(rs.Fields("Date Hired"), "mm/dd/yyyy")
        rs![BirthDate] = Format(rs.Fields("Birthdate"), "mm/dd/") & "2015"
        'rs("VendorYN") = True 'The other way to refer to a field
        rs.Update

        'Example Save contact name into a variable
        'sContactName = rs!FirstName & " " & rs!LastName

        'Move to the next record. Don't ever forget to do this.
        rs.MoveNext
    Loop
Else
    MsgBox "There are no records in the recordset."
End If

MsgBox "Finished looping through records."

rs.Close 'Close the recordset
Set rs = Nothing 'Clean up
End Sub
0
FordraidersAuthor Commented:
Thanks !
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.