Solved

Short dates with starting days 1-12 not being seen 13-31 OK

Posted on 2016-09-16
2
35 Views
Last Modified: 2016-09-16
Hi Experts,

Please find attached Access Form Db.

Please use the FormLookup form and you will notice the Record Name is not being found for certain dates. This would seem to be because the DLookup function is not able to know what is the day and month portion of the date (American and English notation being different) for days 1-12. The DateAdd function does not seem to have this problem and is able to add a day to the correct date.

What is the problem?
DateTest.mdb
0
Comment
Question by:DColin
2 Comments
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 41801139
Set the Format property of your textbox to "Short Date" and you can reduce your code to:
Private Sub Form_Load()

    Me!txtDate.Value = Date

End Sub

Private Sub btnAddDay_Click()

    Me!txtDate.Value = DateAdd("d", 1, Me!txtDate.Value)
    UpdateRecordName Me!txtDate.Value

End Sub

Private Sub btnMinusDay_Click()

    Me!txtDate.Value = DateAdd("d", -1, Me!txtDate.Value)
    UpdateRecordName Me!txtDate.Value

End Sub

Private Sub UpdateRecordName(lookUpDate As Date)

    Me!txtRecordName.Value = DLookup("RecordName", "Table1", "RecordDate = #" & Format(lookUpDate, "yyyy\/mm\/dd") & "#")

End Sub

Open in new window

/gustav
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 41801145
Really though, if you want to go with the table route, your table should have 2 fields.  The first field should contain the numbers 1 thru 31, and the second field should be the spelled out number.  Then you would just do a dlookup of the day portion of your date using the Day() function.

Ron
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

828 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