Results 1 to 2 of 2
  1. #1
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664

    What is this VBA code doing?



    Code:
    Private Sub btnSaveRecord_Click()    
        'Catch error of incomplete form data
        On Error Resume Next
        
            
        'Verify form is filled
        If Me.Dirty Then
            
            'Verify expiration date is later than current date, warn user, and set focus to expiration date field
            If Me.Expiration < Date Then
                MsgBox ("Please enter a valid date")
                txtPropertyExpiration.Value = ""
                txtPropertyExpiration.SetFocus
                Exit Sub
            End If
    
    
            'Attempt to save form.  If incomplete, catch error, resume next
            DoCmd.RunCommand acCmdSaveRecord
            
            If Err.Number <> 0 Then
                MsgBox ("Please Complete the form.  No changes made.")
                Exit Sub
            End If
        
        Else
            'Notify user that Form is empty, can not be saved
            MsgBox ("Please complete the form.  No changes made.")
            Exit Sub
        End If
        
        'Refresh data in the propertyPass subforms (First the current propertyPass, then propertyPass history
        Forms!sfrmPropertyPass1.Requery
        Forms!sfrmPropertyPass.Requery
        Forms!sfrmPropertyPass1.updateButtons
        
        
        'Close NewPropPass form
        DoCmd.Close
    
    
    End Sub


    I know that I have asked this question before.

    The above codes works on my db project. In the frmNewproperty when you click the save button the VBA code is activated.everything works.

    It is what I want, I found the code in a old program and as I said it works.

    I am not sure what it is doing. I understand it is checking on the expiration date, but beyond that it is a mystery.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,645
    Exactly which lines do you not understand? What I see:

    1. use form Dirty property to test if record has changes and proceed accordingly

    2. validation for date values

    3. code to save form but if that results in error message - probably because some required field does not have data - user gets message and Exit Sub executes

    4. if not bypassed by Exit Sub line: refresh subforms and save record and close form - but why refresh subforms if closing form - the only mystery here is what is happening in procedure called by Forms!sfrmPropertyPass1.updateButtons
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 20
    Last Post: 10-13-2015, 09:05 AM
  2. Replies: 3
    Last Post: 10-16-2014, 08:49 AM
  3. Replies: 4
    Last Post: 03-10-2014, 12:18 PM
  4. Replies: 7
    Last Post: 05-28-2013, 09:11 AM
  5. Replies: 1
    Last Post: 05-04-2013, 12:19 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