Results 1 to 5 of 5
  1. #1
    amd711 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2012
    Posts
    28

    Prevent datasheet selection change from saving the current insertion


    In a splitted form, editing through datasheet can be prevented by changing the datasheet properties to read only but changing the selected record by clicking on the side of the datasheet will cause the current insertion -either new record or edited record- to be saved befor moving to the selected record.

    how can i prevent that?

  2. #2
    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
    The short answer is that you can't! In Access, when you move from one Record to another Record, the Current Record is Saved. In a Split Form, when you click on one of the Records, in the Split View portion of the Form, you're moving to another Record, and so the Current Record, shown in the Single View Record portion of the Form, is Saved.

    The only way around this behavior, in Access, is rather convoluted and requires using an Unbound Form, and Unbound Forms can only display one Record at a time, making the Split Form basically useless. Using an Unbound Form, like this, you have to use a Temporary Table to write data to, then write code to use after you've done whatever it is you want to do to Append the Records from the Temp Table to your regular Table. Way more work, in my opinion, to avoid a major default behavior in Access.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    amd711 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2012
    Posts
    28
    so is it possible to:

    1- capture this event. (moving between records using the datasheet). or

    2- make the datasheet completely unabled - just for view.

  4. #4
    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
    Quote Originally Posted by amd711 View Post
    so is it possible to:

    ...capture this event. (moving between records using the datasheet)...
    When moving from Record to Record, the Form_Current event fires. But in a Split Form, any code you might use, in the Form_Current event, to try to work around your problem, will be executed whether you move Record-to-Record in the Datasheet View portion or the Form View portion of the Form.

    Quote Originally Posted by amd711 View Post
    so is it possible to:

    ...make the datasheet completely unabled - just for view.
    No. You can set
    1. The size of the Datasheet portion, in relation to the entire Form
    2. Where it appears, in relation to the Form View portion
    3. Whether or not there is a Separator Bar between the Form View and Datasheet View portions of the Form
    4. Whether or not the user can move the Separator Bar, at runtime, to adjust the size of the Datasheet portion of the Form
    5. Whether or not the Datasheet portion or the Form View portion, of the Form can be printed

    But you cannot 'disable' the Datasheet portion of the Form. If you click on a Record, in the Datasheet View portion of the Form, Access moves to that Record, and the previously selected Record will be Saved. The whole idea behind the development of the Split Form was to allow the user to easily view all Records and quickly select one and move to it.

    About the only thing you can do, here, is to pop a Messagebox asking the user whether or not they want to Save the Current Record, and if they respond 'No,' dump the New Record or dump changes made to an Existing Record.

    Here’s some boilerplate code to do that:

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Not (Me.NewRecord) Then
      If MsgBox("Would You Like To Save The Changes To This Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save Changes to Record ???") = vbNo Then
       Me.Undo
      End If
    Else
      If MsgBox("Would You Like To Save This New Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save This Record ???") = vbNo Then
       Me.Undo
      End If
    End If
    End Sub


    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    amd711 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2012
    Posts
    28
    thanks alot Missinglinq

    i'v already used the "beforeupdate" event, but instead of showing a message, i used a boolean that is set to True if the update process is executed by the form view controls and False otherwise which will result in "me.undo"

    looks like its the only solution

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

Similar Threads

  1. Replies: 3
    Last Post: 09-07-2012, 12:50 PM
  2. Replies: 8
    Last Post: 08-26-2012, 11:11 PM
  3. Saving/Restoring Modified Datasheet Form
    By EddieN1 in forum Programming
    Replies: 1
    Last Post: 01-20-2012, 09:48 PM
  4. Prevent Saving of Form
    By bburton in forum Access
    Replies: 4
    Last Post: 02-25-2011, 09:26 PM
  5. prevent editing current entries in forms
    By Chazcoral in forum Forms
    Replies: 1
    Last Post: 05-20-2010, 06:49 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