Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2015-01-12
9
Medium Priority
?
299 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 39

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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 52

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 52

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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

636 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