MsgBox on change

klr397

Registered User.
Local time
Yesterday, 16:59
Joined
Dec 13, 2005
Messages
30
I have a lastname field that can easily be erased accidentily. so i need to put a piece of code in there that will bring up a msg box that will ask them weather they relly want to change the last name. The code i have so far just brings up a message box but i need it to restore the last name if they do not wish to change it or i need it to go back and allow them to change it. here is what i have so far.

Private Sub LastName_Change()
Dim Answer As Integer
Answer = MsgBox("Do you wish to change this candidates Last Name?",
vbQuestion + vbYesNo, "Question")

If answer= VbYes Then

Else

End If

End Sub

any ideas????
 
Maybe you could use the before update event. Just do a message box and if the select to 'not change', you simply docmd.CancelEvent
???
 
First, change this to run on the BeforeUpdate event. Then, use the code below:

If answer= VbNo Then
Cancel = True
me.LastName.Undo
Else

End If
 
Thanks!!! that helped i went with

Private Sub LastName_AfterUpdate()
Dim strMsg As String
With Me.LastName
If Not IsNull(.OldValue) Then
strMsg = "Change the name from " & .OldValue & _
" to " & Nz(.Value, "nothing") & "?"
If MsgBox(strMsg, vbYesNo + vbQuestion, "Confirm") <> vbYes Then
.Value = .OldValue
End If
End If
End With
 
I use the below code in the AfterUpdate event of a combo box. This should give you an idea on how to test if the value of a non new record for a specific field has been modified. I alert the user with a message box and notify them of the old and new value and let them decide if they want to accept the change or restore the change to the field in question by using the OldValue property.

Code:
    If Not Me.NewRecord Then
        If MsgBox("You have modified the current record for User ID " & Me.cbUserID.OldValue & ".  You have changed the Group from '" & DLookup("[Group]", "tGroups", "[RecordID] = " & "[Forms]![fGroups]![cbGroup].OldValue") & "' to '" & Me.cbGroup.Column(0) & "'." & vbCrLf & vbLf & "Click the 'OK' button to continue with the change or click the 'Cancel' button to undo the modification to the current record." & vbCrLf & vbLf & "Click the 'Add Record' button if you need to add a new record.", vbQuestion + vbOKCancel, "Modified Current Record") = vbCancel Then
            Me.Undo 'user click Cancel
        Else
            'do nothing, user clicked OK
        End If
    End If
 
Here is another option utilizing a cmd button - If the user indeed wants to change the name, they need to first click the 'Change Name' button.

The problem I have run into is that everyone is so 'click' happy that if a box pops up, they are apt to just hit 'okay' to get on with the process.

Code:
Private Sub cmdChgName_Click()
On Error GoTo Err_cmdChgName_Click
Forms!StudentNew!LastName.Locked = False
Forms!StudentNew!FirstName.Locked = False
Forms!StudentNew!Suffix.Locked = False
Forms!StudentNew!MI.Locked = False


Exit_cmdChgName_Click:
    Exit Sub

Err_cmdChgName_Click:
    msgbox Err.Description
    Resume Exit_cmdChgName_Click
    
End Sub

John D
 

Users who are viewing this thread

Back
Top Bottom