Results 1 to 11 of 11
  1. #1
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228

    Close form and dont save record

    I'm trying to find the Before Update event in the event builder and I cant see it anywhere.



    I've seen a few different ways of achieving the same thing but so far nothings worked.

    If a user adds wrong information and choses to close the form then it always saves the data. I only want it saved if the user choses to save it.

    The close button I have has saving turned off but it seems the record has already been updated by that point.

    Thanks in advance,

    Andy.

    Edit - The before update is in form properties, I have found it now. But I cant set the parameter 'Cancel' to True.

    if I look at the forms code this is there,

    Option Compare Database
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    End Sub

  2. #2
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,046
    Hi,
    in such cases I use an unbound form that loads its data through a 'Load' procedure (most of the times after a search action) and then saves the updated data through a the on-click event of a command button.

  3. #3
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    When this code is active nothing will save no matter what I do:
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    Cancel = True
    End Sub
    But here: The setting determines if the BeforeUpdate event occurs. Setting the Cancel argument to True (–1) cancels the BeforeUpdate event.

    What am I doing wrong?

    It seems like this is working as intended to stop the updates, but how do I save now if I want to ?

  4. #4
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,444
    The setting determines if the BeforeUpdate event occurs
    Not quite - the beforeupdate event occurs before the underlying table is updated - setting cancel=true cancels the update so the update never occurs. Try


    Private Sub Form_BeforeUpdate(Cancel As Integer)
    if msgbox("Do you want to update this record",vbyesno)=vbno then Cancel = True
    End Sub

  5. #5
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,444
    suggest you read this link so you understand the order in which events occur

    https://support.office.com/en-ca/art...7-ce86553682f9

    and this one for the different type of events

    https://msdn.microsoft.com/en-us/lib.../jj249049.aspx

  6. #6
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Thank you! This works fine, do you know how to disable the warning when I click to not save?

    "you can't save this record at this time"

    Not a big deal if its difficult, But it would be nice if it wasn't there.

    Cheers!

  7. #7
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,444
    that error covers a number of possible reasons - suggest you google the error and find one of the solutions that works for you

  8. #8
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    The reason is because I just clicked to not save. The reason is fine, and google doesn't come up with much (googled before I asked).

    But its no issue, Thanks again.

  9. #9
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Its still assigning the ID's to the record before its saved. So if a user choses not to save the ID that would have been used cant be used again. NoellaG's suggestion is probably the best for this, but this is already set up how I want it and time is a luxury.

    Do you have any sugestions how to not assign the ID. Or is it even an issue? Obviously bad data isn't ideal but its not massive amounts, just a few numbers that the user cant even see.

    What do you guys think?

    Andy.

  10. #10
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,444
    ID is allocated when a new record is created, it is lost forever if the record is not saved. It shouldn't be an issue an autonumber is just a unique number and shouldn't be given any other meaning - see this link http://www.utteraccess.com/wiki/index.php/Autonumbers

  11. #11
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Yea, but obviously a record is kept that the number has been used. If it happens thousands of times I was thinking it could impact on performance.

    I'm just being picky trying to future proof it as much as possible. But the data is very small and I'm assuming the database wont even look at these as its running. I don't know the exact details of what access looks at on load but in a sequential number I'm assuming it just looks at the last number.

    I have read somewhere you can clean it up in the registry at a later date and re-use the lost numbers.

    Anyway, thanks for the answer. I thought I was making it a bigger deal than it was.

    Andy.

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

Similar Threads

  1. Replies: 3
    Last Post: 08-26-2014, 12:52 PM
  2. do NOT save record on close (x button)
    By benjammin in forum Forms
    Replies: 12
    Last Post: 03-15-2013, 02:54 AM
  3. Can't save or close form
    By Buakaw in forum Forms
    Replies: 4
    Last Post: 07-26-2011, 04:47 AM
  4. Prompt on close and don't save the null record
    By hasanrazaj1 in forum Forms
    Replies: 2
    Last Post: 10-24-2010, 09:24 AM
  5. form won't save and close
    By Philislost in forum Access
    Replies: 6
    Last Post: 10-08-2010, 01:47 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