Solved

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

Posted on 2015-02-20
3
162 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 37

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 48

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 50

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

Independent Software Vendors: 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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

691 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