which event? - for changes in existing records but not new records

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mjvm
    New Member
    • Oct 2008
    • 52

    which event? - for changes in existing records but not new records

    Hi there,

    I have a message box that I want to pop up when a user changes data in an existing record. BUT I don't want it to pop up when a new record is being started, Which event should I put this in?

    I am in Access 2000, and I have set up my message box in the properties table, not in Visual Basic.

    Can I sort this in the Properties table? When I go into Visual Basic - I can't find the code that matches my message box. Is everything in the database in code - I thought it was????

    Thanks if you can help,

    Marcella
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    No, what's in the Properties Sheet is in the Properties Sheet, not in code, and this kind of thing will need to be done thru code.

    You don't say if you want a warning if a certain piece of data is changed or if any change is made to the existing record. Assuming the latter, I think this, placed in the code module of your form, will do what you need done:
    Code:
    Private Sub Form_Dirty(Cancel As Integer)
     If Not Me.NewRecord Then
      Response = MsgBox("You are about to change data in an existing record! Would you like to proceed?", vbYesNo)
       If Response = vbNo Then
        Cancel = True
        Me.Undo
       End If
     End If
    End Sub
    When the user first attempts to change data a message pops up, asking him if this is his/her intention. If the user responds Yes, they are allowed to proceed. If they respond No, the change that has already been made (which is, in fact, only the entering or deletion of a single character) is undone.

    This can be modified if it doesn't meet your exact needs.

    Welcome to Bytes!

    Linq ;0)>

    Comment

    • mjvm
      New Member
      • Oct 2008
      • 52

      #3
      Thanks for the feedback.

      What I wanted to set up was a warning that alerts the user that they have changed data in a saved record with a prompt to undo if the change is not needed.

      I like what you have proposed - but can you please customise it to apply to only two fields - called [School2] and [Student Name].

      In our experience, it is too easy for these fields to be inadvertently changed by a user and we need to protect that data.

      I know I need to work on the naming of my database - I have been directed to the naming conventions by another expert on this forum. Can you tell me if you have any experience using the ACC Technology Renaming Wizard?

      Regards,

      Marcella

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        That's an entirely different can of worms, but doable, of course.

        Code:
        Private Sub Form_BeforeUpdate(Cancel As Integer)
        If Not Me.NewRecord Then
         
         If Me.School2.Value <> Me.School2.OldValue Then
          Response = MsgBox("You are about to change data in the School2 Field! Do you wish to proceed?", vbYesNo)
          If Response = vbNo Then
           Me.School2.Value = Me.School2.OldValue
          End If
         End If
         
         If Me.Student_Name.Value <> Me.Student_Name.OldValue Then
          Response = MsgBox("You are about to change data in the Student Name Field! Do you wish to proceed?", vbYesNo)
          If Response = vbNo Then
           Me.Student_Name.Value = Me.Student_Name.OldValue
          End If
         End If
        
        End If
        End Sub
        Note that when a control's name has a space in it, like "Student Name", Access VBA places an underscore in it to replace the space. So in code, it has to be referred to as Student_Name.

        Sorry, I've never even heard of the ACC Technology Renaming Wizard.

        Linq ;0)>

        Comment

        • mjvm
          New Member
          • Oct 2008
          • 52

          #5
          Thank you! That has worked beautifully just the way I wanted it to!


          Thank you for all your help.

          Comment

          Working...