Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Confirm before Update

Status
Not open for further replies.

MyKidsFirst

Programmer
Oct 16, 2003
7
0
0
US
I found thread 702-559741 to be a solution for a single field update confirmation... However, it doesn't work when you put the same code on multiple fields. Is this because it's in the Before Update event and that applies to the entire record as opposed to a specific field. I'm new to this VB stuff.

I'm simply trying to undo changes on the response "no" for an existing record and not popping up a message on a new record. Seemed like a simple request anyhow. You can see I even tried send keys. Ah well, learning is fun.

I have this for now...I've included notes, old attempts and all (Is that bad etiquette here?):

Private Sub DateReceived_BeforeUpdate(Cancel As Integer)
'Dim Old_Value
'Old_Value = DateReceived.OldValue

Dim strMsg As String
strMsg = "Data has changed."
strMsg = strMsg & "Do you wish to change the Date Received?"
strMsg = strMsg & "Click Yes to Change or No to Discard changes."

If Not Me.NewRecord Then

ElseIf MsgBox(strMsg, vbQuestion + vbYesNo, "Change Received?") = vbYes Then
'do nothing
Else
'SendKeys "{ESC}", True
' DateReceived.Value = Old_Value

DoCmd.CancelEvent

'Cancel = True
End If

End Sub

Regards,
Sheryll
 
use the BeforeUpdate event of the form rather than a specific control.

Code:
private sub Form_BeforeUpdate(cancel as integer)
Dim strMsg As String

strMsg = "Data has changed." & vbcrlf & _
    "Do you wish to save changes the Record?" & _
    vbcrlf & _
    "Click Yes to Save or No to Discard changes."

if not me.newrecord and me.dirty then
    if msgbox(strmsg,vbyesno) = vbno then 
        cancel = true
    end if
end if 
end sub

Alec Doughty
Doughty Consulting P/L

"Life's a competition. Play hard, but play fair"
 
Thank you Alec.

I entered the code on the form's Before Update Event, but, the changes are excepted even when selecting no. I've had this same problem in the past. I've even tried using SendKeys for {ESC}...tee hee....is that cheating? Not working....ugghhh ;-).

regards,
Sheryll
 
Maybe this will do the trick.

Code:
private sub Form_BeforeUpdate(cancel as integer)
Dim strMsg As String

strMsg = "Data has changed." & vbcrlf & _
    "Do you wish to save changes the Record?" & _
    vbcrlf & _
    "Click Yes to Save or No to Discard changes."

if not me.newrecord and me.dirty then
    if msgbox(strmsg,vbyesno) = vbno then 
        [COLOR=red]me.undo[/color]
        cancel = true
    end if
end if 
end sub

Alec Doughty
Doughty Consulting P/L

"Life's a competition. Play hard, but play fair"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top