Select option button when have the name as a string

  • Thread starter Thread starter Debbie Probert via OfficeKB.com
  • Start date Start date
D

Debbie Probert via OfficeKB.com

Hi All

During the running of my VBA code, I collect the name of an option button from an Access database. I then want to set the value of the option button on a form. My problem is that I have the name of the button as a string and just cannot see how to use that to set the value of the button on the form as, when used as a string, I get an error.

Hope the question makes sense to someone :-)

Many thanks
Deb
 
Deb,

Use
Me.Controls(string_value)

with whatever property you want

--
HTH

Bob Phillips

Debbie Probert via OfficeKB.com said:
Hi All

During the running of my VBA code, I collect the name of an option button
from an Access database. I then want to set the value of the option button
on a form. My problem is that I have the name of the button as a string and
just cannot see how to use that to set the value of the button on the form
as, when used as a string, I get an error.
 
Private Sub CommandButton2_Click()
sStr = "Button Name"
UserForm1.Optionbutton1.Caption = sStr
End Sub

I assume by name you mean the name you would see next to the button on the
form.

--
Regaards,
Tom Ogilvy



Debbie Probert via OfficeKB.com said:
Hi All

During the running of my VBA code, I collect the name of an option button
from an Access database. I then want to set the value of the option button
on a form. My problem is that I have the name of the button as a string and
just cannot see how to use that to set the value of the button on the form
as, when used as a string, I get an error.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top