Results 1 to 15 of 15
  1. #1
    emhill57 is offline Novice
    Windows 7 64bit Access 2013 32bit
    Join Date
    May 2017
    Posts
    27

    Leave Data on Add Form


    I have a client that has an individual form for table maintenance and an individual for for table additions. Right now the addition form has a button to click to "Add Record". This button does this in the "onclick" event:

    DoCmd.RunCommand acCmdSaveRecord
    DoCmd.Close

    The client wants to have a button that will add the record but keep the data on the form and make changes to a couple of fields and then add another record until he is ready to close the form. The form does have many fields and he didn't want the screen to clear after the add.

    Would it be best to have the "onclick" event save the screen data to variables then after the DoCmd.RunCommand acCmdSaveRecord is performed to re-populate the fields with the saved variables and let him continue? Is there a simpler way? I know I would need to remove the DoCmd.Close but just wondering if I'm making this harder that I should.

    Thanks!!!!

  2. #2
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    You could use vba to set the default values for those controls to the current values before saving the record.
    Then move to a new record, that way the default values will be loaded, but not saved if you don't save the next record.

  3. #3
    emhill57 is offline Novice
    Windows 7 64bit Access 2013 32bit
    Join Date
    May 2017
    Posts
    27
    Something like this?

    Forms!frmNameFileAdd!NameDate.DefaultValue = Me.NameDate

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    The saving of the data to the table is handled by Access. There is no need for you to do anything at all. The data will stay on the screen until either the form is closed or the Add New button is clicked, at which point the data will be saved to the table. Be sure to set the form's Cycle property to Current Record.

  5. #5
    emhill57 is offline Novice
    Windows 7 64bit Access 2013 32bit
    Join Date
    May 2017
    Posts
    27
    aytee111... just saw that and was about to post. Thanks!!!!

  6. #6
    emhill57 is offline Novice
    Windows 7 64bit Access 2013 32bit
    Join Date
    May 2017
    Posts
    27
    This isn't quite doing what I want. It is leaving the data on the screen like I need but if I make some changes to the screen data and try to add again it just updates that record that was just added instead of adding a new entry with the changes made. Any suggestions?

    Here are my form data properties:

    Click image for larger version. 

Name:	Table Properties.JPG 
Views:	9 
Size:	25.7 KB 
ID:	31460

  7. #7
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Sorry, missed that. You need to change the Add Record button to start a new record, with the code DoCmd.GoToRecord,,acNewRec.

  8. #8
    emhill57 is offline Novice
    Windows 7 64bit Access 2013 32bit
    Join Date
    May 2017
    Posts
    27
    But that then clears the existing data. I think I am going to have to save the current data and then re-populate the fields on the screen after the initial add. Does that sound like what needs to be done?

    I haven't been doing this for long and am still learning.

    Thanks!

  9. #9
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Did you test it? "clears the existing data" tells me nothing - a form shows what it on a table, did the clearing of the form send the data to cyber heaven or store it on a table?

  10. #10
    emhill57 is offline Novice
    Windows 7 64bit Access 2013 32bit
    Join Date
    May 2017
    Posts
    27
    When I first open the form it has no data in it's fields because it is a "Data Entry" form. Once the user enters the data and clicks the "Add" button, in the "onclick" event for the button I save each form field to a save variable and do this:

    DoCmd.RunCommand acCmdSaveRecord
    DoCmd.GoToRecord, , acNewRec

    After that I populate the form fields (which are now cleared due to the acNewRec) with the saved variables.

    This is working just fine but was wondering if I was doing it the most efficient way.

    Thanks!!!!

  11. #11
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    It sounds like we are back to the beginning, come full circle! When a form has a record source, then each field on the form is bound to the underlying table using the Control Source property. That tells Access what data to put where. You seem to be doing all of this manually. Then once you have entered all the data and move off the record, either by closing the form or by going to a new record, then the data is moved to the table. There is no need for any intervention or VBA to accomplish this, it is standard Access behavior.

  12. #12
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Oh wait, I think I have your requirements incorrect!

  13. #13
    emhill57 is offline Novice
    Windows 7 64bit Access 2013 32bit
    Join Date
    May 2017
    Posts
    27
    Yes. I want it to be a data entry only screen. No deletions. No updates. Adds only. When the form is first displayed the bound fields are empty allowing the user to enter the data for the add.

    What I did above is working just fine. Just wanted to make sure I wasn't re-inventing the wheel on this.

    Thanks for your input!

  14. #14
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Sorry about wasting your time, posts # 2 and 3 were following correctly. Just to add quotes (if a text field) or hash (if date field).

  15. #15
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    As aytee111 said, each Datatype needs a different delimiter, or you can simply use this syntax for each one:

    Code:
    Private Sub YourControlName_AfterUpdate()
       Me.YourControlName.DefaultValue = """" & Me.YourControlName.Value & """"
    End Sub

    The nice thing about this code is that it is valid for Text, Number, Date and Yes/No Datatypes!

    You’ll need to do this, of course, for each Control you want to carry forward.

    Linq ;0)>

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

Similar Threads

  1. Cannot leave subform new record
    By sovereign in forum Forms
    Replies: 1
    Last Post: 08-26-2015, 09:51 AM
  2. Help with Leave Calendar database please
    By zbratsberg in forum Access
    Replies: 2
    Last Post: 09-15-2013, 06:16 AM
  3. Half-day leave computation
    By bsvubana in forum Access
    Replies: 5
    Last Post: 11-29-2012, 02:28 AM
  4. Annual Leave Planner
    By Dexter in forum Access
    Replies: 1
    Last Post: 03-01-2011, 05:00 AM
  5. help need on query report on who is on leave
    By islandboy in forum Forms
    Replies: 10
    Last Post: 08-17-2009, 12:13 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