?
Solved

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

Posted on 2015-02-20
3
Medium Priority
?
166 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 38

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 48

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 51

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

764 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