Any one spot the mistake?

colinmunnelly

Registered User.
Local time
Today, 23:36
Joined
Feb 26, 2002
Messages
89
The code below brings up a "Do you want to save message box" problem is for some reason it saves even if you press No. Can anybody spot the problem?


Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Msg, Style, Response, MyString
Beep
Msg = "Do you wish to save this record?"
Style = vbYesNo + vbExclamation + vbDefaultButton1 'define buttons
Title = "Confirm Save" '
respnse = MsgBox(Msg, Style, Title)
If Response = vbNo Then
Me.Undo
Exit Sub
DoCmd.RunCommand acCmdSaveRecord
End If

End Sub
 
If Response = VbYes Then
DoCmd.RunCommand acCmdSaveRecord
Else
Me.Undo
Exit Sub
End if

I think!!

Col
 
Always add option explicit to your code - it will then identify any non-dimmed variables. you had a typo with 'Response'
Try this

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Msg, Style, Response, MyString
Beep
Msg = "Do you wish to save this record?"
Style = vbYesNo + vbExclamation + vbDefaultButton1 'define buttons
Title = "Confirm Save" '
Response = MsgBox(Msg, Style, Title)

If Response = vbNo Then
Me.Undo
Exit Sub

Else DoCmd.RunCommand acCmdSaveRecord
End If
 
Last edited:
Error message now

getting an error when saving now. I am using v2000 am i right in thinking it may be a problem with the runcommand? did this get upgraded in version 2000? just a thought
 
done it

works fine now. Thanks everyone for your time. If anyone is interested i solved it by removing the accmdsaverecord line.
 
After the following line, you should cancel the update:

Me.Undo
Cancel = True

And there is no need to exit sub so you should remove that line.
 

Users who are viewing this thread

Back
Top Bottom