Solved

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

Posted on 2015-02-20
3
140 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 34

Accepted Solution

by:
PatHartman earned 250 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 47

Expert Comment

by:Dale Fye (Access MVP)
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 49

Assisted Solution

by:Gustav Brock
Gustav Brock earned 250 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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 …

708 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

14 Experts available now in Live!

Get 1:1 Help Now