Access Form - Enter text day name (Sun) based on another field

Posted on 2008-11-11
Last Modified: 2013-11-28
I have a form that includes a date txtDate.  I would like the next field txtDay to be the three letter name for txtDate.  So, if txtDate is 11/11/2008 I would like txtDay to autopopulate with Tue.

I have tried the attached code as an event in the AfterUpdate.

Any ideas?

Thank you in advance.
Private Sub txtDate_AfterUpdate()

       If Format([txtDate], "w") = 1 Then

       Me.txtDay = "Sun"

        ElseIf Format([txtDate], "w") = 2 Then

       Me.txtDay = Mon

        ElseIf Format([txtDate], "w") = 3 Then

       Me.txtDay = Tue

        ElseIf Format([txtDate], "w") = 4 Then

       Me.txtDay = Wed

        ElseIf Format([txtDate], "w") = 5 Then

       Me.txtDay = Thu

        ElseIf Format([txtDate], "w") = 6 Then

       Me.txtDay = Fri

        ElseIf Format([txtDate], "w") = 7 Then

       Me.txtDay = Sat

       End If

End Sub

Open in new window

Question by:Scamquist
    LVL 77

    Accepted Solution

    LVL 1

    Author Closing Comment

    I wanted to keep txtDay as text.  I thought a format command would force me to change it to a date field.  Your answer was about as concise and easy to apply as possible.  Thank you

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
    Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
    In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
    With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now