Solved

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

Posted on 2015-02-20
3
157 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 35

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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.

809 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