By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,285 Members | 1,619 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,285 IT Pros & Developers. It's quick & easy.

use option buttons to change control source

P: 2
I would like to use a set of three option buttons on a form so that depending on which one is selected a text box is bound to one of three corresponding fields. I'm not really sure what the code is to change the control source. Any help would be great.

Ty
Aug 7 '07 #1
Share this Question
Share on Google+
3 Replies


puppydogbuddy
Expert 100+
P: 1,923
I would like to use a set of three option buttons on a form so that depending on which one is selected a text box is bound to one of three corresponding fields. I'm not really sure what the code is to change the control source. Any help would be great.

Ty
Place your option buttons in an option group frame. The option group allows only one button at a time to be selected, and will track and perform actions based on the selection. Sample code is illustrated below. Replace X with the actual name of your option group, and replace the other generic object names I used for illustrative purposes.:
Expand|Select|Wrap|Line Numbers
  1. Private Sub optgrpX_AfterUpdate()
  2.  
  3. 'load appropriate control source for textbox1
  4. Select Case Me![optgrpX]
  5.     Case 1
  6.          Me!txtbox1.ControlSource  = field1
  7.     Case 2
  8.          Me!txtbox1.ControlSource  = field2
  9.     Case 3
  10.          Me!txtbox1.ControlSource  = field3
  11. End Select
Aug 7 '07 #2

P: 2
Thanks for the help, I just started working with access and am still having a little trouble. I'm using access 2007, so I'm now creating an option group by using the option group tool. I enter my three differnt options in the wizard, then after it's created I clicked on the option group frame and in the afterupdate event I created the new event procedure and entered that code. Is this right, or should I be doing it a different way, because I still haven't got it to work yet. Thanks.

Ty
Aug 7 '07 #3

puppydogbuddy
Expert 100+
P: 1,923
Thanks for the help, I just started working with access and am still having a little trouble. I'm using access 2007, so I'm now creating an option group by using the option group tool. I enter my three differnt options in the wizard, then after it's created I clicked on the option group frame and in the afterupdate event I created the new event procedure and entered that code. Is this right, or should I be doing it a different way, because I still haven't got it to work yet. Thanks.

Ty
Sounds like you did it ok, but the values and names of the option groups and buttons have to be assigned also by invoking the property sheet. Example for illustration purposes...you must use the actual names of your objects.

option buttons:
>>>Names: optbtn1, optbtn2, optbtn3
>>> option values: 1, 2, and 3 respectively

option group frame:
>>>>>name:optgrpInquiries
>>>>>default value: 0 if you don't want any of the buttons selected by default, or the value of the button you want as the default

in the code I gave you previously, Case 1 would correspond to selecting optbtn1 with a value of 1.
Aug 7 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.