Results 1 to 5 of 5
  1. #1
    kpo's Avatar
    kpo is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2012
    Posts
    38

    Save/Add Record and Start New Record buttons


    I created a form to enter new records into my database. I need to add two buttons at the end. One that will save the record info I just entered and start a new record. Another to save the record info I just entered and close the form. I have been searching and searching for the correct VBA code to use for these but what I have tried isn't saving the record into the source database. It is like it disappearing into thin air.

    When I created the form I used the "Add Existing Fields" feature to add the correct fields to my form. I thought that would allow them to be linked to the correct table. Was I wrong?

    Thanks in advance for the help!

  2. #2
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    75
    Your form should be bound to the table you are entering into: check the forms Recordsource property to make sure you are bound to a table. If the form is bound the only code you really need behind the button is something like this:
    use any of these behind your save button
    Docmd.Refresh
    or
    docmd.runcommand accmdSaveRecord

    To save and exit just add this to the above code:
    Docmd.Close acform, "[yourformnamehere]"

  3. #3
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    75
    Also, the fields on your form should be bound to a controlSource so make sure you check each textbox ControlSource property.

    To go to next record use this:
    docmd.RunCommand accmdRecordsGotoNew

  4. #4
    kpo's Avatar
    kpo is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2012
    Posts
    38
    Thank you so much!

    the RecordSource and ControlSource are linked to the right place. I tried


    DoCmd.RunCommand acCmdRecordsGoToNew


    and this is what popped up...



    Run-time error '2046':

    The comand or action 'RecordsGoToNew' isn't available now.


    I know it is difficult to troubleshoot when you can't see what I have done :/ I appreciate the help so much! if you need anymore details just ask.

    THANK YOU!!

  5. #5
    kpo's Avatar
    kpo is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2012
    Posts
    38
    I fixed it. (haha for now)

    I had the wrong field set up as the primary key and that was throwing everything off.

    THANK YOU!!

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

Similar Threads

  1. Replies: 2
    Last Post: 04-26-2012, 11:12 AM
  2. Replies: 1
    Last Post: 06-01-2011, 06:44 PM
  3. Record navigation buttons work backward
    By jonesy29847 in forum Access
    Replies: 22
    Last Post: 04-11-2011, 06:17 AM
  4. Make command buttons unique to a record
    By timmy in forum Forms
    Replies: 26
    Last Post: 03-09-2011, 09:51 AM
  5. Replies: 1
    Last Post: 03-09-2009, 12:46 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