LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Set OptionBox value via VBA

I just though I'd post the results of my experience trying to do something
which I would have thought would be simple. In the end it was simple, but you
have to know some somewhat obsure things to do it right, apparently.
The task:
An (Userforms/MSForms, NOT an ActiveX) Group control and two enclosed Option
button controls (one for Yes, one for No) are on a spreadsheet. Set the
option button value(s) to Yes or No via VBA code as read from a database
field.
How would you think this would be done?
Set the value of the ONE control which is "Picked"/On to True(=-1 in VBA),
right? Wrong. Set it to the constant value xlON (= 1 in VBA).
Also, it seems to depend upon whether the control is bound to a cell in a
workbook or not. According to my recent experience, if you do this:
ActiveWorksheet.Shapes("OptionButton1").ControlFor mat.Value = xlOn
This will set an option button to ON. Interestingly, if you wish to set that
same option button to OFF you need the xlOFF constant, whose value is NOT 0
(which is what VB programmers might intuitively think it ought to be), it is
-4146. go figure.

However, this may - or may not - work properly if you are setting the value
of a control that IS bound to a worksheet cell (i.e.
ActiveWorksheet.Shapes("OptionButton1").LinkedCell ="B19" ).
In that circumstance, you may be better off in changing the option button
values by changing the cell value directly.
But, what values do you use to set the option buttons in the cell? xlON and
xlOff, right? wrong.
The values you need to set in the cell are 2 or 3 in this example. 2!??
3!??? Where the HECK did those values come from? I haven't a clue. Ths only
way I found out what the values to use was to set up the control, bind them
to a common cell, and click them each, observing what values appeared in the
cell.
Well, at leasst it worked, and hopefully, this should help someone else
puzzle through this forms-control-in-worksheet weirdness too.

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set Optionbox value from code? Mark Burns Excel Programming 2 March 5th 09 04:46 PM
Code for OptionBox Noepie Excel Programming 2 December 12th 08 10:30 AM
Excel Checkboxs, Optionbox Brandon Excel Discussion (Misc queries) 1 January 19th 07 08:25 PM
optionbox checkbox flow23 Excel Discussion (Misc queries) 3 November 24th 05 01:00 PM
OptionBox error checking Patrick Simonds Excel Programming 1 September 29th 05 08:39 AM


All times are GMT +1. The time now is 08:03 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"