Results 1 to 10 of 10
  1. #1
    ShennyP is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    11

    Holding/Keeping fields after record added


    I have tried a few things I have found going through Google but have not found a solution that has worked.

    I have a form which has 5 values and then 2 sub forms. When it is all filled in and the "Add Record" button is hit I want to be able to keep the previous entry for 4 of the fields. These fields are a date, a combo box and 2 times. Basically when this form is being used there are multiple entries with the same 4 values for these fields and it would be a large time saver to leave them as the previous record.

    What is the easiest way to do this? I would like to try and avoid using another button to retrieve the old values if possible.

    Cheers

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,915
    Use code in each control's AfterUpdate event to set its DefaultValue property.

    http://access.mvps.org/access/forms/frm0012.htm
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ShennyP is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    11
    Quote Originally Posted by June7 View Post
    Use code in each control's AfterUpdate event to set its DefaultValue property.

    http://access.mvps.org/access/forms/frm0012.htm
    I am not too familiar with access, would I use that code in the AfterUpdate and that is it?

    I may need a bit more detail.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,915
    Yes, as I said, just each control AfterUpdate event.

    Or behind the button you already have. Your choice.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    ShennyP is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    11
    I managed to get it to work with this

    Private Sub Production_Date_AfterUpdate()


    If Not IsNull(Me.Production_Date.Value) Then
    Production_Date.DefaultValue = "#" & Me.Production_Date & "#"
    End If


    End Sub

    However for some reason the month and day switch on me when it loads the default value. So ive put in 1st of march and hit next record and it goes to the 3rd of Jan. Any thoughts?

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,915
    Where are you located?

    Review http://allenbrowne.com/ser-36.html

    Non-U.S. style date is not an issue I have to deal with so not quite sure how you need to manage this.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    ShennyP is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    11
    Quote Originally Posted by June7 View Post
    Where are you located?

    Review http://allenbrowne.com/ser-36.html

    Non-U.S. style date is not an issue I have to deal with so not quite sure how you need to manage this.
    Australia. I may start a thread as I am sure I am not the first to come across this issue

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,915
    It is a very common topic.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Quote Originally Posted by ShennyP View Post
    I managed to get it to work with this

    Private Sub Production_Date_AfterUpdate()


    If Not IsNull(Me.Production_Date.Value) Then
    Production_Date.DefaultValue = "#" & Me.Production_Date & "#"
    End If


    End Sub

    However for some reason the month and day switch on me when it loads the default value. So ive put in 1st of march and hit next record and it goes to the 3rd of Jan. Any thoughts?
    You have to use US format (m/d/yyyy) when you insert a date through VBA code.
    Give it a try as below:
    Code:
    If Not IsNull(Me.Production_Date.Value) Then
      Production_Date.DefaultValue = "#" & month(Me.Production_Date) & "/" & day(Me.Production_Date) & "/" & year(Me.Production_Date) & "#"
    End If

  10. #10
    ShennyP is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    11
    Quote Originally Posted by accesstos View Post
    You have to use US format (m/d/yyyy) when you insert a date through VBA code.
    Give it a try as below:
    Code:
    If Not IsNull(Me.Production_Date.Value) Then
      Production_Date.DefaultValue = "#" & month(Me.Production_Date) & "/" & day(Me.Production_Date) & "/" & year(Me.Production_Date) & "#"
    End If
    Seems to have worked! Thanks

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 09-25-2018, 05:33 PM
  2. Keeping on the same record while changing forms
    By TomBrierley in forum Forms
    Replies: 5
    Last Post: 09-04-2016, 08:25 PM
  3. Replies: 1
    Last Post: 12-23-2014, 01:23 PM
  4. Replies: 2
    Last Post: 01-03-2012, 06:54 PM
  5. Replies: 5
    Last Post: 06-29-2010, 01:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums