?
Solved

Fill date field with value from previous record if a new record

Posted on 2015-01-12
9
Medium Priority
?
298 Views
Last Modified: 2015-01-12
I have a form with a date field.  If the user is entering a new record I want that date field to auto-fill with the date from the previous record.

How?
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
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 38

Expert Comment

by:PatHartman
ID: 40544728
from the previous record.
At any point in time, the "Previous" record could be any record of the set or no record at all if you are looking at the first record of a set.  Previous has no meaning in a relational database since tables/queries are unordered sets unless you sort them by something.  You would need to tell us precisely what you mean by previous and how to handle the "no previous" situation.

The date may belongs in the parent record so it doesn't have to be duplicated.
0
 

Author Comment

by:SteveL13
ID: 40544817
Regarding... "You would need to tell us precisely what you mean by previous and how to handle the "no previous" situation."...

Suppose on the form I filled in a date of 11/1/2013.  When I go to the next NEW record I want the field to automatically fill with 11/1/2013.  But if I open the database again and go to a new record, I want the date field to be blank.

--Steve
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40545084
when you save the record, place the value of the date to a variable

tempvars.add "mydate", me.txtDatexx.value

then when creating new record, use it to fill the date

if me.newrecord and Nz(tempvars!mydate,"") <>"" then
  me.txtDatexx=tempvars!mydate
end if
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 51

Expert Comment

by:Gustav Brock
ID: 40545123
You would use the DefaultValue for this:

Private Sub txtDate_AfterUpdate()
    With Me!txtDate
        .DefaultValue = "#" & Format(.Value, "mm\/dd\/yyyy") & "#"
    End With
End Sub

Clear the value when opening the form (will also work when opening the app several times a day):

    Me!txtDate.DefaultValue = ""

/gustav
0
 

Author Comment

by:SteveL13
ID: 40545130
Is not working quite right.  When I enter a new record the date goes back to the first record entered date.  See attachment.
Remember-last-value-entered.accdb
0
 

Author Comment

by:SteveL13
ID: 40545131
Whoops!  My reply was for Rey.  I'll try Gustav suggestion.
0
 

Author Comment

by:SteveL13
ID: 40545146
Gustav solution not working either See attached.
Remember-last-value-entered.accdb
0
 
LVL 51

Accepted Solution

by:
Gustav Brock earned 1000 total points
ID: 40545162
It's working great if you put the code where it should be:

Private Sub txtDateEntered_BeforeUpdate(Cancel As Integer)
     With Me!txtDateEntered
         .DefaultValue = "#" & Format(.Value, "mm\/dd\/yyyy") & "#"
     End With
End Sub

You may wish to skip updating with Null:

Private Sub txtDateEntered_BeforeUpdate(Cancel As Integer)
     With Me!txtDateEntered
        If Not IsNull(.Value) Then
            .DefaultValue = "#" & Format(.Value, "mm\/dd\/yyyy") & "#"
        End If
     End With
End Sub

/gustav
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 1000 total points
ID: 40545180
steve

you have to move the form to new record, your form is in edit mode..

click the New record first, enter the info then click Add Record
Remember-last-value-entered.accdb
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
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.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

801 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