Consulting

Results 1 to 2 of 2

Thread: Saving Record in Access

  1. #1

    Saving Record in Access

    Hi,

    Whenever I try to enter any record in the access form, it saves the record by default. how to get rid of this? i do not want records to be saved until it is asked to save.

    please help me.......

    Yogeshwar Vats

  2. #2
    I recommend using the Form's Before Update event.

    Example:

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    
     Cancel = False
    
    
    ' perform data validation
    If IsNull(Me.CompanyName) Then
    
       MsgBox "You must enter a Company Name.", vbCritical, "Data entry error..."
          
       Cancel = True
    
    End If
    
    
    If Not Cancel Then
      ' passed the validation process
    
        If Me.NewRecord Then
            If MsgBox("Data will be saved, Are you Sure?", vbYesNo, "Confirm") = vbNo Then
                Cancel = True
            Else
                ' run code for new record before saving
            
            End If
        
        
        Else
            If MsgBox("Data will be modified, Are you Sure?", vbYesNo, "Confirm") = vbNo Then
                Cancel = True
            Else
               ' run code before an existing record is saved
               ' example: update date last modified
                
            End If
        End If
    
    End If
    
    
    ' if the save has been canceled or did not pass the validation , then ask to Undo changes
    If Cancel Then
    
        If MsgBox("Do you want to undo all changes?", vbYesNo, "Confirm") = vbYes Then
            Me.Undo
    
        End If
        
    End If
    
    End Sub
    Boyd Trimmell aka HiTechCoach
    Microsoft Access MVP -2010-2015

    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •