set option button to true

crowegreg

Registered User.
Local time
Today, 10:39
Joined
Feb 28, 2011
Messages
108
On a form I have 10 option buttons. Named option1, option2, option3..

If I create a recordset which the contains the option buttons I would like set to true, what is the sytax for setting that option button to true?

An example, if my recordset returns the following:
option3
option7
option9

Normally I would just use the command me.option3=true. What's the syntax within the loop for setting those options to true?
 
You can write a loop to set the value of all options to false like...
Code:
dim i as integer
for i = 1 to 10
  me.controls("option" & i) = false
next
Then, since it appears that your recordset does not contain all the options from 1 to 10, you could traverse the fields in the recordset, selecting only those that seem to have an 'option' value, like...
Code:
dim rst as dao.recordset
dim fld as dao.field
set rst = currentdb.openrecordset("OpenYourRecordsetHere")
[COLOR="Green"]'traverse recordset fields collection[/COLOR]
for each fld in rst fields
[COLOR="Green"]  'if the current field name is an 'option', then...[/COLOR]
  if left(fld.name, len("option")) = "option" then
[COLOR="Green"]    'assign it's value to the same named control[/COLOR]
    me.controls(fld.name) = fld.value
  end if
next
 
I understand what you've suggested, but that doesn't solve my question.Is their anyway to use the values that are within my recordset, and set those options to true.

Using this example:
buttons are named, option1, option2, option3...option10

my recordset returns: option3, option5, option7, option9

Instead of having a command for each item within the recordset, is their anyway to write a loop that sets only those buttons to being true
 
I understand what you've suggested, but that doesn't solve my question.Is their anyway to use the values that are within my recordset, and set those options to true.

Using this example:
buttons are named, option1, option2, option3...option10

my recordset returns: option3, option5, option7, option9

Instead of having a command for each item within the recordset, is their anyway to write a loop that sets only those buttons to being true
Lagbolt already gave you the answer.
http://www.access-programmers.co.uk/forums/showpost.php?p=1168187&postcount=2
 
Thanks lagbolt and Bob. I didn't see lagbolt's reply until Bob mentioned it. that's exactly what I needed!!
 
Last edited:

Users who are viewing this thread

Back
Top Bottom