Why wont it do?

thorpyuk

Well-known Member
Joined
Mar 14, 2006
Messages
1,453
Dim bfr As Long
bfr = ComboBox1.Value
ComboBox1.Value = bfr: Exit Sub

how come this gives me a "cant change property" error!?

The code is inside my combobox change event...
 

Some videos you may like

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,079
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
So you want to change the value inside the change event (and change it to what it already is)? Why???
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,218
Office Version
  1. 365
Platform
  1. Windows
And you want to change the value to the value it was in the first place?:eek:
 

thorpyuk

Well-known Member
Joined
Mar 14, 2006
Messages
1,453
Apologies for the protracted reply....

It's a snippet of code.

I basically have an exception whereby if a user selects a certain option from the combobox, they get a msgbox, and it exits the routine.

The problem is that the value in the combobox changes, so i wanted a way of reverting it back to what it was originally, if that makes sense? :>
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,079
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS

ADVERTISEMENT

Why is the value in the combobox then??
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,218
Office Version
  1. 365
Platform
  1. Windows
Well of course it changes - the user picked it.:)

Do you mean you want to revert to the value they had chosen before they chose the one that displays the messagebox?

That's could be possible but it's probably going to be a bit messy if it is.

Is there a reason the value is included in the list?
 

gecs

Active Member
Joined
Jan 26, 2009
Messages
320

ADVERTISEMENT

You may use the Enter event to save the value of the control in a variable before that value is changed and then use the BeforeUpdate event to test the value, display the message and change the control's value back to what it was.
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,079
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
You may use the Enter event to save the value of the control in a variable before that value is changed and then use the BeforeUpdate event to test the value, display the message and change the control's value back to what it was.

If you exit the control to run the code, then yes. (that is my preferred method too) If you want the code to run without the focus leaving the combobox, as with the Change event, then BeforeUpdate isn't triggered at the right time.
 

gecs

Active Member
Joined
Jan 26, 2009
Messages
320
It's also possible to test the new value, display the message and change the value back inside the Change event.
 

thorpyuk

Well-known Member
Joined
Mar 14, 2006
Messages
1,453
Well of course it changes - the user picked it.:)

Do you mean you want to revert to the value they had chosen before they chose the one that displays the messagebox?

Hi Norie - yes, that's exactly what i'd like to do...

GECS - Thanks for your suggestion, i'll look into it...

Rorya - any chance of a cup of tea please? :>

P.S - apologies for the really long pauses before replying! :s
 

Watch MrExcel Video

Forum statistics

Threads
1,122,705
Messages
5,597,663
Members
414,162
Latest member
jborjal1967

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top