Results 1 to 3 of 3
  1. #1
    carmenv323 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Location
    Massachusetts
    Posts
    78

    Dirty not saving- record

    Hello All,

    I have my submit button with the following code which should save the record when it gets to If Me.Dirty Then. When I step through the code it highlights the code Me.Dirty = False suggesting that it's saving it because then it goes to BeforeUpdate to CheckValidation (checking for errors) but there's nothing to validate because the record isn't saved in the table. I'm scratching my head because it was working fine and now it's not! This is the very first step in a long process to test and I can't get past the first part. Please help

    Code:
    Private bFailValidation As Boolean
    Private tSave As Integer
    Code:
    Private Sub btnSubmitAndClose_Click()
        Dim Cancel As Integer
            Cancel = 0
            tSave = 1
    On Error GoTo ErrorHandler
            If Me.Dirty Then
                Me.Dirty = False    
            Else
            Dim r As VbMsgBoxResult
                r = MsgBox("Are you sure you want to submit with no changes?", vbYesNo, "Submit?")
                    If r = vbYes Then
                        CheckValidation Me, Cancel, bWO
                        bFailValidation = Cancel
                            If bFailValidation = False Then
                                UpdateData
                            End If
                    ElseIf Cancel = True Then
                        Exit Sub
                    End If
            End If
            If tSave = 0 Then
                Me.Requery
                Me.KeyPreview = False
            End If
        
                Me.Requery
                    Exit Sub
    ErrorHandler: 'DEBUG
      MsgBox "Submit ERROR: " & Err.Number & " " & Err.Description
    End Sub




    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    On Error GoTo ErrorHandler
        If tSave = 0 Then  'Exit if no validation needed
            Exit Sub
            
        ElseIf tSave = 1 Then
            CheckValidation Me, Cancel, bWO
    
    
            bFailValidation = Cancel
            
    '        If bFailValidation = False Then
            UpdateData
    '        End If
            
        ElseIf tSave = 2 Then
            Exit Sub
        End If
    
    
        Exit Sub
        
            Exit Sub
    ErrorHandler: 'DEBUG
      MsgBox "BeforeUpdate ERROR: " & Err.Number & " " & Err.Description
    End Sub

  2. #2
    carmenv323 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Location
    Massachusetts
    Posts
    78
    I moved some code around (basically off the BeforeUpdate event and it worked fine.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,861
    You are not dimming variables like tSave?, are they Globals?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Saving a new record
    By justme4 in forum Access
    Replies: 8
    Last Post: 09-17-2019, 04:20 PM
  2. Replies: 1
    Last Post: 11-19-2018, 07:57 PM
  3. Replies: 5
    Last Post: 12-12-2013, 10:13 PM
  4. On Dirty fires but Me.Dirty = False (v2010)
    By Rod in forum Programming
    Replies: 5
    Last Post: 07-30-2011, 08:42 PM
  5. Saving Record
    By mwabbe in forum Programming
    Replies: 12
    Last Post: 09-15-2010, 12:09 PM

Tags for this Thread

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