Results 1 to 5 of 5
  1. #1
    LAazsx is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Posts
    30

    stopping a form from saving records

    Hi, i want to make a "save" button for my form. Is there a way to prevent the form from writing records instantly? and how do i code the button to "save" the record?
    Last edited by LAazsx; 12-09-2010 at 05:49 PM.

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    a form, technically, is just a table that looks different. that's why the records do that.

    if you use:
    Code:
    me.undo
    you can reverse any updates made to a form record, and even cancel the entry of a new record, by checking the:
    Code:
    me.newrecord
    property.

    on a button like that, more than likely this would be fine:
    Code:
    runcommand accmdsaverecord
    the:
    Code:
    docmd.save
    doesn't do anything different than the runcommand for the record does. to my knowledge, that's only useful in design view, which is impossible of course.

  3. #3
    LAazsx is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Posts
    30
    Quote Originally Posted by ajetrumpet View Post

    if you use:
    Code:
    me.undo
    you can reverse any updates made to a form record, and even cancel the entry of a new record, by checking the:
    Code:
    me.newrecord
    property.
    Sorry for the stupid question but where do i enter me.undo? and is me.newrecord the same as allow additions?

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Code:
    me.newrecord
    is a property of the form. the return is a boolean. true or false. the return tells you if the current record is a new entry or not.

    Code:
    allowadditions
    is the same thing. it's a property, nothing else. the setting of it (true or false) allows or not, the addition of new records through the interface. for instance, if you put a button on a form and put some new record code behind it, chances are access will error because it violates the "allowadditions" property that is set to "false". does that make sense?


    all of these things are just tools at your disposal, as the programmer, that you can use to control user activity.

    Code:
    me.undo
    like I said before, undoes any changes made to the CURRENT record only. it applies to one record at a time, and no more. you can call it a million times if you want. you can also put it in code at any time you want. it doesn't matter. but, to my knowledge, it will only do anything for you if changes have been made to the record.

    so if your button takes the user to a new record, but they've changed the one they're on already, you can throw a message box to them and save the changes or not based on what they tell you. you would do so like this:
    Code:
    on button_click
    
    if me.dirty then
       if msgbox("Hey!  you changed this rec's data.  should I save it for you?", vbyesno) = vbno then
          me.undo
             'GOTO new rec here
       else
             'JUST go to new rec
    end if
    hopefully that is clearer for you, and you can run with it! also please know, that the code I write on this forum I usually write by hand, as examples, so copying it and pasting it verbatim into a vb editor will surely not work for you the first time, unless I get lucky. (I'm no expert, just an experienced guy).

  5. #5
    LAazsx is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Posts
    30
    i think i got it. thanks

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

Similar Threads

  1. Saving records when a button is pushed
    By LAazsx in forum Programming
    Replies: 1
    Last Post: 11-28-2010, 10:06 PM
  2. Closing and saving a form
    By Lxmanager in forum Forms
    Replies: 14
    Last Post: 11-21-2010, 02:04 AM
  3. Event Stopping - need help please
    By TG_W in forum Forms
    Replies: 3
    Last Post: 05-20-2010, 09:25 AM
  4. saving records without null or empty fields
    By amber mara in forum Access
    Replies: 1
    Last Post: 05-05-2010, 02:34 PM
  5. Saving records in multiple sub forms
    By niak32 in forum Forms
    Replies: 0
    Last Post: 10-13-2008, 04:24 AM

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