Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Why new record defaulting to 12/30/1899 ???

Posted on 2015-02-20
3
Medium Priority
?
173 Views
Last Modified: 2015-02-24
On a form I have a date field.  The user enters a date sometimes in the past, sometimes he may enter today's date.

Then on the form I have an [Add Record] command button.  When the button is clicked the form displays a new record but the date is populated with 12/30/1899 !!!!   What?  Why?

Here is the onclick code of the command button:

Private Sub txtTranxDate_AfterUpdate()

    Me!txtTranxDate.DefaultValue = Me!txtTranxDate.Value

End Sub

Open in new window


All I want the date field to populate with is the last date entered in the record prior to the new one.
0
Comment
Question by:SteveL13
3 Comments
 
LVL 40

Accepted Solution

by:
PatHartman earned 1000 total points
ID: 40621524
12/30/1899 is the "0" date.  Therefore, Me.txtTranxDate must contain zero.

"Last" is a meaningless term in a relational database so I presume that you mean the record entered immediately prior to the current one.  What if this is the "first" record?

One method is to define a tempvar to hold the last entered value.  So in the AfterUpdate event of the date control, store the entered value in the tempvar.  Then in the BeforeInsert event of your form, populate the date with the tempvar value.  don't forget to check for null so you can substitute today's date - Date() or whatever makes sense.
0
 
LVL 49

Expert Comment

by:Dale Fye
ID: 40621561
Check the default value of the control and of the field in your table.  It should be blank if you want new records to come up blank.
0
 
LVL 52

Assisted Solution

by:Gustav Brock
Gustav Brock earned 1000 total points
ID: 40621986
Replace with this code:

    With Me!txtTranxDate
        If Not IsNull(.Value) Then
            .DefaultValue = "#" & Format(.Value, "yyyy\/mm\/dd") & "#"
        End If
    End With

/gustav
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Suggested Courses

805 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