Any one spot the mistake? (1 Viewer)

colinmunnelly

Registered User.
Local time
Today, 11:37
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
 

ColinEssex

Old registered user
Local time
Today, 11:37
Joined
Feb 22, 2002
Messages
9,126
If Response = VbYes Then
DoCmd.RunCommand acCmdSaveRecord
Else
Me.Undo
Exit Sub
End if

I think!!

Col
 

Fizzio

Chief Torturer
Local time
Today, 11:37
Joined
Feb 21, 2002
Messages
1,885
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:

colinmunnelly

Registered User.
Local time
Today, 11:37
Joined
Feb 26, 2002
Messages
89
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
 

colinmunnelly

Registered User.
Local time
Today, 11:37
Joined
Feb 26, 2002
Messages
89
done it

works fine now. Thanks everyone for your time. If anyone is interested i solved it by removing the accmdsaverecord line.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:37
Joined
Feb 19, 2002
Messages
43,457
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

Top Bottom