PC Review


Reply
Thread Tools Rate Thread

cancel a combobox change

 
 
Mike Archer
Guest
Posts: n/a
 
      7th Apr 2010
Hello. I want to be able to cancel a combobox change. Cancel is not
parameter in the change event, and there is not a beforechange event. I have
pasted my attempt below. No matter what item is selected in the event for
the combobox, it always changes back to whatever the user selected at the
conclusion of the event. Is there a work around that would effectivly be the
same as canceling the change?

Private Sub ComboBox1_Change()
Dim RUSure As Integer, GoBack As Integer
GoBack = ComboBox1.ListIndex 'set the goback value in case user wants to
cancel.
If SavedList = False Then
RUSure = MsgBox("Do you want discard changes to the list?", vbYesNo)
If RUSure = vbYes Then
SavedList = True
Else
ComboBox1.ListIndex = GoBack 'This line is my attempt to change it
back.
Exit Sub
End If
End If
ListBox2.Clear
If ComboBox1.ListIndex > -1 Then
For Each v In ThisWorkbook.Worksheets("SkillsDetails").Range("A:A")
If v = Empty Then Exit For
If v = ComboBox1.Text Then
ListBox2.AddItem v.Offset(0, 1).Value
End If
Next v
End If
End Sub




--
Thanks,
Mike
 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      7th Apr 2010
It could be done with a simple loop that prevents any action being taken as
a result of the change unless the message box response equals vbYes,

RETRY:
'Code that calls the UserForm for the combobox
Private Sub ComboBox1_Change()
Ans = MsgBox("Are you sure the selection/entry is correct", _
vbYesNo, "VALIDATE")
If Ans = vbNo Then
GoTo RETRY:
End If
'Continue code execution
End Sub




"Mike Archer" <(E-Mail Removed)> wrote in message
news:5F7207B9-3DEB-4384-8CE4-(E-Mail Removed)...
> Hello. I want to be able to cancel a combobox change. Cancel is not
> parameter in the change event, and there is not a beforechange event. I
> have
> pasted my attempt below. No matter what item is selected in the event for
> the combobox, it always changes back to whatever the user selected at the
> conclusion of the event. Is there a work around that would effectivly be
> the
> same as canceling the change?
>
> Private Sub ComboBox1_Change()
> Dim RUSure As Integer, GoBack As Integer
> GoBack = ComboBox1.ListIndex 'set the goback value in case user wants to
> cancel.
> If SavedList = False Then
> RUSure = MsgBox("Do you want discard changes to the list?", vbYesNo)
> If RUSure = vbYes Then
> SavedList = True
> Else
> ComboBox1.ListIndex = GoBack 'This line is my attempt to change it
> back.
> Exit Sub
> End If
> End If
> ListBox2.Clear
> If ComboBox1.ListIndex > -1 Then
> For Each v In ThisWorkbook.Worksheets("SkillsDetails").Range("A:A")
> If v = Empty Then Exit For
> If v = ComboBox1.Text Then
> ListBox2.AddItem v.Offset(0, 1).Value
> End If
> Next v
> End If
> End Sub
>
>
>
>
> --
> Thanks,
> Mike



 
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
combobox after change but user hits cancel to message box VBANovice Microsoft Excel Programming 5 5th Mar 2010 11:14 PM
datagrid, change combobox value at run time based on the value of another combobox at different column zhuang Microsoft Dot NET Framework Forms 0 23rd Feb 2006 05:04 PM
ComboBox BeforeUpdate Cancel not working Stef Microsoft Access Form Coding 4 21st Oct 2005 04:01 PM
How to cancel ComboBox choice.. Pawel Janik Microsoft Dot NET Framework Forms 2 30th Jun 2004 08:22 AM
cancel combobox update Patrick McGuire Microsoft Access Form Coding 0 3rd Dec 2003 08:32 PM


Features
 

Advertising
 

Newsgroups
 


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