PC Review


Reply
Thread Tools Rate Thread

combobox after change but user hits cancel to message box

 
 
VBANovice
Guest
Posts: n/a
 
      5th Mar 2010
the code below is used to save some data when a user changes months on a
combobox. The code prompts the user to see if he/she wants to save the
estimates with a Yes, No, Cancel.

yes and no cases work as expected but when the user clicks cancel, the code
exits out as expected but the combox box value is now set to the new month
the user selected. I would like it to be set back to the month they had in
the combox before the changed it.

how can I do modify the code to do that or is there a better way to do this?

thanks

Private Sub cboMonth_Change()
Dim myCheck As Integer
Dim ms As String
Dim dc As Long

On Error Resume Next
Application.ScreenUpdating = False

ms = Format(Range("cyMonthSave"), "mmm")

With Sheets("Estimates")

'finds appropriate column
dc = .Rows(1).Find(What:=ms, LookIn:=xlValues, LookAt _
:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Column

End With
If Sheets("Merchandise Store Plan").Range("m15").Value =
Sheets("Estimates").Cells(60, dc).Value Then
GoTo SkipChanges:
End If

myCheck = MsgBox("Do you want to save your changes?", vbYesNoCancel, "Save")

If myCheck = vbCancel Then
Exit Sub
Else
If myCheck = vbNo Then
GoTo SkipChanges:
End If
End If

mcrSaveEstimates

'No changes to save
SkipChanges:

Range("A2") = Sheets("Misc").Range("CYMonth").Value
Range("A3") = Sheets("Misc").Range("PYMonth").Value

'brings back previosly saved estimated for the new month selected
RestoreEstimates

Application.ScreenUpdating = True
Beep
End Sub
 
Reply With Quote
 
 
 
 
Paul Robinson
Guest
Posts: n/a
 
      5th Mar 2010
Hi
Why have a cancel?
regards
Paul

On Mar 5, 3:02*pm, VBANovice <VBANov...@discussions.microsoft.com>
wrote:
> the code below is used to save some data when a user changes months on a
> combobox. *The code prompts the user to see if he/she wants to save the
> estimates with a Yes, No, Cancel.
>
> yes and no cases work as expected but when the user clicks cancel, the code
> exits out as expected but the combox box value is now set to the new month
> the user selected. *I would like it to be set back to the month they had in
> the combox before the changed it. *
>
> how can I do modify the code to do that or is there a better way to do this?
>
> thanks
>
> Private Sub cboMonth_Change()
> Dim myCheck As Integer
> Dim ms As String
> Dim dc As Long
>
> On Error Resume Next
> Application.ScreenUpdating = False
>
> ms = Format(Range("cyMonthSave"), "mmm")
>
> With Sheets("Estimates")
>
> 'finds appropriate column
> dc = .Rows(1).Find(What:=ms, LookIn:=xlValues, LookAt _
> :=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
> MatchCase:=False, SearchFormat:=False).Column
>
> End With
> If Sheets("Merchandise Store Plan").Range("m15").Value =
> Sheets("Estimates").Cells(60, dc).Value Then
> GoTo SkipChanges:
> End If
>
> myCheck = MsgBox("Do you want to save your changes?", vbYesNoCancel, "Save")
>
> If myCheck = vbCancel Then
> * * Exit Sub
> * *Else
> * *If myCheck = vbNo Then
> * * *GoTo SkipChanges:
> * *End If
> End If
>
> mcrSaveEstimates
>
> 'No changes to save
> SkipChanges:
>
> Range("A2") = Sheets("Misc").Range("CYMonth").Value
> Range("A3") = Sheets("Misc").Range("PYMonth").Value
>
> 'brings back previosly saved estimated for the new month selected
> RestoreEstimates
>
> Application.ScreenUpdating = True
> Beep
> End Sub


 
Reply With Quote
 
VBANovice
Guest
Posts: n/a
 
      5th Mar 2010
because the user might change their mind and not want to save what they have
just entered. lot's a cells are impacted.

"Paul Robinson" wrote:

> Hi
> Why have a cancel?
> regards
> Paul
>
> On Mar 5, 3:02 pm, VBANovice <VBANov...@discussions.microsoft.com>
> wrote:
> > the code below is used to save some data when a user changes months on a
> > combobox. The code prompts the user to see if he/she wants to save the
> > estimates with a Yes, No, Cancel.
> >
> > yes and no cases work as expected but when the user clicks cancel, the code
> > exits out as expected but the combox box value is now set to the new month
> > the user selected. I would like it to be set back to the month they had in
> > the combox before the changed it.
> >
> > how can I do modify the code to do that or is there a better way to do this?
> >
> > thanks
> >
> > Private Sub cboMonth_Change()
> > Dim myCheck As Integer
> > Dim ms As String
> > Dim dc As Long
> >
> > On Error Resume Next
> > Application.ScreenUpdating = False
> >
> > ms = Format(Range("cyMonthSave"), "mmm")
> >
> > With Sheets("Estimates")
> >
> > 'finds appropriate column
> > dc = .Rows(1).Find(What:=ms, LookIn:=xlValues, LookAt _
> > :=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
> > MatchCase:=False, SearchFormat:=False).Column
> >
> > End With
> > If Sheets("Merchandise Store Plan").Range("m15").Value =
> > Sheets("Estimates").Cells(60, dc).Value Then
> > GoTo SkipChanges:
> > End If
> >
> > myCheck = MsgBox("Do you want to save your changes?", vbYesNoCancel, "Save")
> >
> > If myCheck = vbCancel Then
> > Exit Sub
> > Else
> > If myCheck = vbNo Then
> > GoTo SkipChanges:
> > End If
> > End If
> >
> > mcrSaveEstimates
> >
> > 'No changes to save
> > SkipChanges:
> >
> > Range("A2") = Sheets("Misc").Range("CYMonth").Value
> > Range("A3") = Sheets("Misc").Range("PYMonth").Value
> >
> > 'brings back previosly saved estimated for the new month selected
> > RestoreEstimates
> >
> > Application.ScreenUpdating = True
> > Beep
> > End Sub

>
> .
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      5th Mar 2010
Instead of tying this to the _Change event, why not have a "ok" button that does
the work.

The user changes the month and hits ok. You do some validity checks and do the
work if everything is ok.



VBANovice wrote:
>
> the code below is used to save some data when a user changes months on a
> combobox. The code prompts the user to see if he/she wants to save the
> estimates with a Yes, No, Cancel.
>
> yes and no cases work as expected but when the user clicks cancel, the code
> exits out as expected but the combox box value is now set to the new month
> the user selected. I would like it to be set back to the month they had in
> the combox before the changed it.
>
> how can I do modify the code to do that or is there a better way to do this?
>
> thanks
>
> Private Sub cboMonth_Change()
> Dim myCheck As Integer
> Dim ms As String
> Dim dc As Long
>
> On Error Resume Next
> Application.ScreenUpdating = False
>
> ms = Format(Range("cyMonthSave"), "mmm")
>
> With Sheets("Estimates")
>
> 'finds appropriate column
> dc = .Rows(1).Find(What:=ms, LookIn:=xlValues, LookAt _
> :=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
> MatchCase:=False, SearchFormat:=False).Column
>
> End With
> If Sheets("Merchandise Store Plan").Range("m15").Value =
> Sheets("Estimates").Cells(60, dc).Value Then
> GoTo SkipChanges:
> End If
>
> myCheck = MsgBox("Do you want to save your changes?", vbYesNoCancel, "Save")
>
> If myCheck = vbCancel Then
> Exit Sub
> Else
> If myCheck = vbNo Then
> GoTo SkipChanges:
> End If
> End If
>
> mcrSaveEstimates
>
> 'No changes to save
> SkipChanges:
>
> Range("A2") = Sheets("Misc").Range("CYMonth").Value
> Range("A3") = Sheets("Misc").Range("PYMonth").Value
>
> 'brings back previosly saved estimated for the new month selected
> RestoreEstimates
>
> Application.ScreenUpdating = True
> Beep
> End Sub


--

Dave Peterson
 
Reply With Quote
 
Paul Robinson
Guest
Posts: n/a
 
      5th Mar 2010
Hi
I can't see the combobox_change making any changes to cell values.

Are you making changes before you have checked whether the changes
should be made? If you are, they need to be made after the message box
check.
regards
Paul

On Mar 5, 4:33*pm, VBANovice <VBANov...@discussions.microsoft.com>
wrote:
> because the user might change their mind and not want to save what they have
> just entered. *lot's a cells are impacted. *
>
> "Paul Robinson" wrote:
> > Hi
> > Why have a cancel?
> > regards
> > Paul

>
> > On Mar 5, 3:02 pm, VBANovice <VBANov...@discussions.microsoft.com>
> > wrote:
> > > the code below is used to save some data when a user changes months on a
> > > combobox. *The code prompts the user to see if he/she wants to savethe
> > > estimates with a Yes, No, Cancel.

>
> > > yes and no cases work as expected but when the user clicks cancel, the code
> > > exits out as expected but the combox box value is now set to the new month
> > > the user selected. *I would like it to be set back to the month they had in
> > > the combox before the changed it. *

>
> > > how can I do modify the code to do that or is there a better way to do this?

>
> > > thanks

>
> > > Private Sub cboMonth_Change()
> > > Dim myCheck As Integer
> > > Dim ms As String
> > > Dim dc As Long

>
> > > On Error Resume Next
> > > Application.ScreenUpdating = False

>
> > > ms = Format(Range("cyMonthSave"), "mmm")

>
> > > With Sheets("Estimates")

>
> > > 'finds appropriate column
> > > dc = .Rows(1).Find(What:=ms, LookIn:=xlValues, LookAt _
> > > :=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
> > > MatchCase:=False, SearchFormat:=False).Column

>
> > > End With
> > > If Sheets("Merchandise Store Plan").Range("m15").Value =
> > > Sheets("Estimates").Cells(60, dc).Value Then
> > > GoTo SkipChanges:
> > > End If

>
> > > myCheck = MsgBox("Do you want to save your changes?", vbYesNoCancel, "Save")

>
> > > If myCheck = vbCancel Then
> > > * * Exit Sub
> > > * *Else
> > > * *If myCheck = vbNo Then
> > > * * *GoTo SkipChanges:
> > > * *End If
> > > End If

>
> > > mcrSaveEstimates

>
> > > 'No changes to save
> > > SkipChanges:

>
> > > Range("A2") = Sheets("Misc").Range("CYMonth").Value
> > > Range("A3") = Sheets("Misc").Range("PYMonth").Value

>
> > > 'brings back previosly saved estimated for the new month selected
> > > RestoreEstimates

>
> > > Application.ScreenUpdating = True
> > > Beep
> > > End Sub

>
> > .


 
Reply With Quote
 
VBANovice
Guest
Posts: n/a
 
      5th Mar 2010
If it was just Yes/No, wouldn't they still be able to close the window with
the X on the top right?

"Paul Robinson" wrote:

> Hi
> Why have a cancel?
> regards
> Paul
>
> On Mar 5, 3:02 pm, VBANovice <VBANov...@discussions.microsoft.com>
> wrote:
> > the code below is used to save some data when a user changes months on a
> > combobox. The code prompts the user to see if he/she wants to save the
> > estimates with a Yes, No, Cancel.
> >
> > yes and no cases work as expected but when the user clicks cancel, the code
> > exits out as expected but the combox box value is now set to the new month
> > the user selected. I would like it to be set back to the month they had in
> > the combox before the changed it.
> >
> > how can I do modify the code to do that or is there a better way to do this?
> >
> > thanks
> >
> > Private Sub cboMonth_Change()
> > Dim myCheck As Integer
> > Dim ms As String
> > Dim dc As Long
> >
> > On Error Resume Next
> > Application.ScreenUpdating = False
> >
> > ms = Format(Range("cyMonthSave"), "mmm")
> >
> > With Sheets("Estimates")
> >
> > 'finds appropriate column
> > dc = .Rows(1).Find(What:=ms, LookIn:=xlValues, LookAt _
> > :=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
> > MatchCase:=False, SearchFormat:=False).Column
> >
> > End With
> > If Sheets("Merchandise Store Plan").Range("m15").Value =
> > Sheets("Estimates").Cells(60, dc).Value Then
> > GoTo SkipChanges:
> > End If
> >
> > myCheck = MsgBox("Do you want to save your changes?", vbYesNoCancel, "Save")
> >
> > If myCheck = vbCancel Then
> > Exit Sub
> > Else
> > If myCheck = vbNo Then
> > GoTo SkipChanges:
> > End If
> > End If
> >
> > mcrSaveEstimates
> >
> > 'No changes to save
> > SkipChanges:
> >
> > Range("A2") = Sheets("Misc").Range("CYMonth").Value
> > Range("A3") = Sheets("Misc").Range("PYMonth").Value
> >
> > 'brings back previosly saved estimated for the new month selected
> > RestoreEstimates
> >
> > Application.ScreenUpdating = True
> > Beep
> > End Sub

>
> .
>

 
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
cancel a combobox change Mike Archer Microsoft Excel Programming 1 7th Apr 2010 08:17 PM
User hits Cancel The Inspector Microsoft Excel Programming 3 29th Jun 2009 12:58 PM
Making A Call To The API When A User Hits A Button To Retrieve TheCurrent System User Name R Tanner Microsoft Access Forms 1 9th Jan 2009 07:58 PM
Cancel Macro is user selects 'cancel' at save menu =?Utf-8?B?TWFyaw==?= Microsoft Excel Programming 1 6th Apr 2005 05:45 PM
Dialog Box - User hits cancel Michael Hopwood Microsoft Excel Programming 4 14th Nov 2003 10:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:39 AM.