PC Review


Reply
Thread Tools Rate Thread

Cancel / Comfirm update

 
 
Eoin McGlynn
Guest
Posts: n/a
 
      9th Feb 2010
I am trying to use VBA to confirm or cancel a change to a combo box. I have
the code below on the "before update" property: However I am told the discard
changes command is not available. I have also tried the acUndo commnad and
the cancel=true statement.

Private Sub Membership_Grade_BeforeUpdate(Cancel As Integer)

On Error GoTo MebershipTitleUpdate_Err
Dim strMsg As String
Dim UsrResponse As Integer

' Specify the message to display.
strMsg = "This will update the Membership Grade and chane the associated
subscription fee." & Chr(10)
strMsg = strMsg & "Click Yes to Save or No to Discard changes."

' Display the message box.
UsrResponse = MsgBox(strMsg, vbQuestion + vbYesNo, "Comitt Changes")

' Check the user's response.
If iResponse = vbYes Then

DoCmd.beep

Else

' Cancel the update.
DoCmd.RunCommand acCmdDiscardChanges

End If

MebershipTitleUpdate_Exit:
Exit Sub

MebershipTitleUpdate_Err:
MsgBox Error$
Resume MebershipTitleUpdate_Exit



End Sub

 
Reply With Quote
 
 
 
 
Daryl S
Guest
Posts: n/a
 
      9th Feb 2010
Eoin -

Just set

Cancel = True

This will cancel the update.
--
Daryl S


"Eoin McGlynn" wrote:

> I am trying to use VBA to confirm or cancel a change to a combo box. I have
> the code below on the "before update" property: However I am told the discard
> changes command is not available. I have also tried the acUndo commnad and
> the cancel=true statement.
>
> Private Sub Membership_Grade_BeforeUpdate(Cancel As Integer)
>
> On Error GoTo MebershipTitleUpdate_Err
> Dim strMsg As String
> Dim UsrResponse As Integer
>
> ' Specify the message to display.
> strMsg = "This will update the Membership Grade and chane the associated
> subscription fee." & Chr(10)
> strMsg = strMsg & "Click Yes to Save or No to Discard changes."
>
> ' Display the message box.
> UsrResponse = MsgBox(strMsg, vbQuestion + vbYesNo, "Comitt Changes")
>
> ' Check the user's response.
> If iResponse = vbYes Then
>
> DoCmd.beep
>
> Else
>
> ' Cancel the update.
> DoCmd.RunCommand acCmdDiscardChanges
>
> End If
>
> MebershipTitleUpdate_Exit:
> Exit Sub
>
> MebershipTitleUpdate_Err:
> MsgBox Error$
> Resume MebershipTitleUpdate_Exit
>
>
>
> End Sub
>

 
Reply With Quote
 
Eoin McGlynn
Guest
Posts: n/a
 
      10th Feb 2010
I tried that but it didn't work.

"Daryl S" wrote:

> Eoin -
>
> Just set
>
> Cancel = True
>
> This will cancel the update.
> --
> Daryl S
>
>
> "Eoin McGlynn" wrote:
>
> > I am trying to use VBA to confirm or cancel a change to a combo box. I have
> > the code below on the "before update" property: However I am told the discard
> > changes command is not available. I have also tried the acUndo commnad and
> > the cancel=true statement.
> >
> > Private Sub Membership_Grade_BeforeUpdate(Cancel As Integer)
> >
> > On Error GoTo MebershipTitleUpdate_Err
> > Dim strMsg As String
> > Dim UsrResponse As Integer
> >
> > ' Specify the message to display.
> > strMsg = "This will update the Membership Grade and chane the associated
> > subscription fee." & Chr(10)
> > strMsg = strMsg & "Click Yes to Save or No to Discard changes."
> >
> > ' Display the message box.
> > UsrResponse = MsgBox(strMsg, vbQuestion + vbYesNo, "Comitt Changes")
> >
> > ' Check the user's response.
> > If iResponse = vbYes Then
> >
> > DoCmd.beep
> >
> > Else
> >
> > ' Cancel the update.
> > DoCmd.RunCommand acCmdDiscardChanges
> >
> > End If
> >
> > MebershipTitleUpdate_Exit:
> > Exit Sub
> >
> > MebershipTitleUpdate_Err:
> > MsgBox Error$
> > Resume MebershipTitleUpdate_Exit
> >
> >
> >
> > End Sub
> >

 
Reply With Quote
 
Daryl S
Guest
Posts: n/a
 
      10th Feb 2010
Eoin -

You are assigning the response from the MsgBox to the variable UsrResponse,
but you are checking the variable iResponse. Change one of those to match
the other...

--
Daryl S


"Eoin McGlynn" wrote:

> I tried that but it didn't work.
>
> "Daryl S" wrote:
>
> > Eoin -
> >
> > Just set
> >
> > Cancel = True
> >
> > This will cancel the update.
> > --
> > Daryl S
> >
> >
> > "Eoin McGlynn" wrote:
> >
> > > I am trying to use VBA to confirm or cancel a change to a combo box. I have
> > > the code below on the "before update" property: However I am told the discard
> > > changes command is not available. I have also tried the acUndo commnad and
> > > the cancel=true statement.
> > >
> > > Private Sub Membership_Grade_BeforeUpdate(Cancel As Integer)
> > >
> > > On Error GoTo MebershipTitleUpdate_Err
> > > Dim strMsg As String
> > > Dim UsrResponse As Integer
> > >
> > > ' Specify the message to display.
> > > strMsg = "This will update the Membership Grade and chane the associated
> > > subscription fee." & Chr(10)
> > > strMsg = strMsg & "Click Yes to Save or No to Discard changes."
> > >
> > > ' Display the message box.
> > > UsrResponse = MsgBox(strMsg, vbQuestion + vbYesNo, "Comitt Changes")
> > >
> > > ' Check the user's response.
> > > If iResponse = vbYes Then
> > >
> > > DoCmd.beep
> > >
> > > Else
> > >
> > > ' Cancel the update.
> > > DoCmd.RunCommand acCmdDiscardChanges
> > >
> > > End If
> > >
> > > MebershipTitleUpdate_Exit:
> > > Exit Sub
> > >
> > > MebershipTitleUpdate_Err:
> > > MsgBox Error$
> > > Resume MebershipTitleUpdate_Exit
> > >
> > >
> > >
> > > End Sub
> > >

 
Reply With Quote
 
Eoin McGlynn
Guest
Posts: n/a
 
      11th Feb 2010
It still does not work

"Daryl S" wrote:

> Eoin -
>
> You are assigning the response from the MsgBox to the variable UsrResponse,
> but you are checking the variable iResponse. Change one of those to match
> the other...
>
> --
> Daryl S
>
>
> "Eoin McGlynn" wrote:
>
> > I tried that but it didn't work.
> >
> > "Daryl S" wrote:
> >
> > > Eoin -
> > >
> > > Just set
> > >
> > > Cancel = True
> > >
> > > This will cancel the update.
> > > --
> > > Daryl S
> > >
> > >
> > > "Eoin McGlynn" wrote:
> > >
> > > > I am trying to use VBA to confirm or cancel a change to a combo box. I have
> > > > the code below on the "before update" property: However I am told the discard
> > > > changes command is not available. I have also tried the acUndo commnad and
> > > > the cancel=true statement.
> > > >
> > > > Private Sub Membership_Grade_BeforeUpdate(Cancel As Integer)
> > > >
> > > > On Error GoTo MebershipTitleUpdate_Err
> > > > Dim strMsg As String
> > > > Dim UsrResponse As Integer
> > > >
> > > > ' Specify the message to display.
> > > > strMsg = "This will update the Membership Grade and chane the associated
> > > > subscription fee." & Chr(10)
> > > > strMsg = strMsg & "Click Yes to Save or No to Discard changes."
> > > >
> > > > ' Display the message box.
> > > > UsrResponse = MsgBox(strMsg, vbQuestion + vbYesNo, "Comitt Changes")
> > > >
> > > > ' Check the user's response.
> > > > If iResponse = vbYes Then
> > > >
> > > > DoCmd.beep
> > > >
> > > > Else
> > > >
> > > > ' Cancel the update.
> > > > DoCmd.RunCommand acCmdDiscardChanges
> > > >
> > > > End If
> > > >
> > > > MebershipTitleUpdate_Exit:
> > > > Exit Sub
> > > >
> > > > MebershipTitleUpdate_Err:
> > > > MsgBox Error$
> > > > Resume MebershipTitleUpdate_Exit
> > > >
> > > >
> > > >
> > > > End Sub
> > > >

 
Reply With Quote
 
Daryl S
Guest
Posts: n/a
 
      11th Feb 2010
Eoin -

Can you be more explicit in what is 'not working'?

If you want to see the old value replaced, add this code (assuming the
control name is Membership_Grade):
Me.Membership_Grade = Me.Membership_Grade.OldValue

If you want to prevent a record from being saved without confirmation, then
the msgBox and Cancel shoud be used in the Form_BeforeUpdate event instead of
a field update event.

If you think there is something wrong with the logic, set a breakpoint and
step through it and see if the If statement are being evaluated as expected,
and check the values of the variables.

--
Daryl S


"Eoin McGlynn" wrote:

> It still does not work
>
> "Daryl S" wrote:
>
> > Eoin -
> >
> > You are assigning the response from the MsgBox to the variable UsrResponse,
> > but you are checking the variable iResponse. Change one of those to match
> > the other...
> >
> > --
> > Daryl S
> >
> >
> > "Eoin McGlynn" wrote:
> >
> > > I tried that but it didn't work.
> > >
> > > "Daryl S" wrote:
> > >
> > > > Eoin -
> > > >
> > > > Just set
> > > >
> > > > Cancel = True
> > > >
> > > > This will cancel the update.
> > > > --
> > > > Daryl S
> > > >
> > > >
> > > > "Eoin McGlynn" wrote:
> > > >
> > > > > I am trying to use VBA to confirm or cancel a change to a combo box. I have
> > > > > the code below on the "before update" property: However I am told the discard
> > > > > changes command is not available. I have also tried the acUndo commnad and
> > > > > the cancel=true statement.
> > > > >
> > > > > Private Sub Membership_Grade_BeforeUpdate(Cancel As Integer)
> > > > >
> > > > > On Error GoTo MebershipTitleUpdate_Err
> > > > > Dim strMsg As String
> > > > > Dim UsrResponse As Integer
> > > > >
> > > > > ' Specify the message to display.
> > > > > strMsg = "This will update the Membership Grade and chane the associated
> > > > > subscription fee." & Chr(10)
> > > > > strMsg = strMsg & "Click Yes to Save or No to Discard changes."
> > > > >
> > > > > ' Display the message box.
> > > > > UsrResponse = MsgBox(strMsg, vbQuestion + vbYesNo, "Comitt Changes")
> > > > >
> > > > > ' Check the user's response.
> > > > > If iResponse = vbYes Then
> > > > >
> > > > > DoCmd.beep
> > > > >
> > > > > Else
> > > > >
> > > > > ' Cancel the update.
> > > > > DoCmd.RunCommand acCmdDiscardChanges
> > > > >
> > > > > End If
> > > > >
> > > > > MebershipTitleUpdate_Exit:
> > > > > Exit Sub
> > > > >
> > > > > MebershipTitleUpdate_Err:
> > > > > MsgBox Error$
> > > > > Resume MebershipTitleUpdate_Exit
> > > > >
> > > > >
> > > > >
> > > > > End Sub
> > > > >

 
Reply With Quote
 
New Member
Join Date: May 2010
Posts: 1
 
      2nd May 2010
I wonder if you have tried the "Undo" method for the control?
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Update or cancel update without addnew or edit error -2147352567 =?Utf-8?B?Um9iaW4=?= Microsoft Access VBA Modules 1 8th Sep 2006 03:51 PM
in outlook,to comfirm an email link,it won't work =?Utf-8?B?Y2hyaXN0b3BoZXIgbGVlIG11cnJheQ==?= Microsoft Access Getting Started 1 18th Apr 2006 05:31 PM
Blank record and error 'Update or Cancel Update without AddNew or Edit' louise Microsoft Access Form Coding 1 21st Feb 2005 01:22 AM
comfirm data changes Knowlton Microsoft Access Forms 3 15th Feb 2004 05:06 PM
before i hit comfirm on the order button...... Chris Corbett DIY PC 3 7th Jan 2004 02:08 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:42 AM.