Results 1 to 7 of 7
  1. #1
    TAM is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2015
    Posts
    22

    Hit "cancel", but record still creates.

    When I launch my modal, I want the user to be able to 'cancel' without creating a new record. It's not doing that and creating extra 'junk' in my table. How do I prevent that?



    Here's my code:
    Private Sub Btn_Exception_SubModal_Click()
    DoCmd.OpenForm "Frm_Exception_UpdateModal", acNormal, , acFormAdd

    Forms! [Frm_Exception_UpdateModal]![clientnmbr].value = Me![clientnmbr].value
    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    the cancel has to be in the record form_BeforeUpdate event
    THEN the cancel = true , will cancel the save.

  3. #3
    TAM is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2015
    Posts
    22
    Thanks for the quick reply! I'm not familiar as to where to find the "form_BeforeUpdate" event. I don't see it in the design view property sheet choice of events. Can you coach me on how to add this to my code, please?

  4. #4
    TAM is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2015
    Posts
    22
    Sorry - found this event on the subform. What specifically should I add for the code builder?

  5. #5
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Code:
    sub form_BeforeUpdate(cancel)
    
    if "record is wrong by your reasons" then
       cancel = true 
    endif
    
    

  6. #6
    TAM is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2015
    Posts
    22
    To clarify -- I added "cancel = true", but I want to control the error message that displays. How do I over-ride the message "You can't save this record at this time. Adjustments may have encountered an error while trying to save a record. If you close this object now, the data changes you made will be lost. Do you want to close the database object anyway?". I'd like to display a custom message more meaningful to the user.

    Thanks again for your help! I'm a beginner, so it takes me a bit!

  7. #7
    nick404's Avatar
    nick404 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2015
    Location
    Wisconsin
    Posts
    352
    Place this on your BeforeUpdate or wherever the error message is displaying from.
    Code:
    Sub Form_BeforeUpdate(Cancel as Integer) -- OR somewhere else 
    On Error GoTo err_proc
    
    -your code-
    
    err_proc:
    MsgBox "Your message text to user", vbYesNo, "Message Title"
    Exit Sub
    
    End Sub
    link to more on message boxes.
    Last edited by nick404; 07-31-2015 at 11:25 AM. Reason: forget ending code tag

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

Similar Threads

  1. Replies: 1
    Last Post: 07-18-2015, 07:59 PM
  2. Replies: 8
    Last Post: 07-15-2014, 05:56 PM
  3. Suppress "Error" message following "Cancel = True"
    By GraeagleBill in forum Programming
    Replies: 7
    Last Post: 03-23-2014, 05:40 PM
  4. Replies: 7
    Last Post: 11-30-2013, 12:33 PM
  5. Replies: 0
    Last Post: 03-11-2012, 09:19 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