I am trying to make a code, where a Msgbox shoud appear if a certain statement is true (to values in a variable is not the same). And afterwards the replay to yes and no should also have a function. I can´t get the code to work. I does show the msgbox when I write this code, but it also shows it when the first statement is not true (when the two values are equal to each other), where I just want it to move on to the next cell (called p_navn). The code is as follows:
Private Sub p_center_LostFocus()
Dim Msg, style, title, Response
style = vbYesNo + vbInformation + vbDefaultButton1
title = "Advarsel"
Msg = "Værdien stemmer ikke overens med første indtastning" & vbNewLine & vbNewLine & _
"Gammel indtastning = " & Me.center.Value & vbNewLine & "Ny indtastning = " & Me.p_center.Value & vbNewLine & vbNewLine & _
"Vil du beholde den nye indtastede værdi?" & vbNewLine & vbNewLine & _
"(Hvis svaret er nej, vil værdien blive ændret til den oprindelige indtastede værdi)"
Response = MsgBox(Msg, style, title)
If Me.p_center.Value = Me.center.Value Then
Exit Sub
ElseIf Me.p_center.Value <> Me.center.Value Then
MsgBox Msg, style, title
If Response = vbYes Then
Me.p_center = Me.p_center.Value
Else
If Response = vbNo Then
Me.p_center = Me.center.Value
End If
End If
End If
End Sub
Hope somebody can help me with this.
Sincerely, swh86