Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WON'T LET ME ADD MORE THAN ONE LABEL TO AN OPTION GROUP CONTROL 1

Status
Not open for further replies.

hazlehurstga

Programmer
Sep 4, 2003
19
0
0
US
I'm running into problems when I try to create an OptionGroup with more than one label. The general text of my code is as follows:

'First I create a new OptionGroup control:
Set ctlText = CreateControl(CurForm.Name, acOptionGroup, acDetail, "", "", 1440, 1440)

'Then I add the first label and option button, bounding them to the ctlText OptionGroup previously created:
Set ctlLabel = CreateControl(CurForm.Name, acLabel, , ctlText.Name, "", (1440*7.2847), (1440*0.875)))
Set ctlButton = CreateControl(CurForm.Name, acOptionButton, , ctlText.Name, "", (1440*7.2800), (1440*0.875)))

'I run into problems when I attempt to add and bound a second label to the same ctlText OptionGroup:
Set ctlLabel = CreateControl(CurForm.Name, acLabel, acDetail, ctlText.Name, "", (1440*7.2847), (1440*1.1042))

I get the following error message when the compiler attempts to excute the previous line above:

"The parent control can't contain the type of control you selected."

Can someone please tell me where I went wrong.

Thank you!!
 
You're trying to add 2 labels to the option group - and it can only have 1 label, normally displayed at the upper left of the frame.

What you need to do is attach the labels to the radio buttons instead. Try this:
Code:
Sub CreateOptionGroup()
  Dim ctlLabel As Label
  Dim ctlButton As OptionButton
  Dim ctlText As OptionGroup
  Dim curForm As Form
  
  DoCmd.OpenForm "OptionGroupDemo", acDesign
  Set curForm = Forms("OptionGroupDemo").Form
  
    'First I create a new OptionGroup control:
  Set ctlText = CreateControl(curForm.Name, acOptionGroup, acDetail, "", "", 1440, 1440, 1440 * 3, 1440 * 2)
  
  
  'This label is added to the option group as a caption label - which is the only label that
  'can be attached to the option group (or "Frame" as some call it).
  Set ctlLabel = CreateControl(curForm.Name, acLabel, , ctlText.Name, "", ctlText.Left + 100, ctlText.Top - 150, 1440, 300)
  ctlLabel.Caption = "My Option Group"
  
  'This creates the radio button
  Set ctlButton = CreateControl(curForm.Name, acOptionButton, , ctlText.Name, "", (1440 + ctlText.Left), (1440 + ctlText.Top))
  
  'This adds a label to the option button - not the option group:
  Set ctlLabel = CreateControl(curForm.Name, acLabel, acDetail, ctlButton.Name, "", ctlButton.Left + 300, ctlButton.Top, 1440, 300)
  ctlLabel.Caption = "Option 1"
  
  DoCmd.Close acForm, curForm.Name, acSavePrompt

End Sub


VBSlammer
redinvader3walking.gif

Unemployed in Houston, Texas
 
VBSlammer,
You are wonderful and a life saver. Thanks so much!! I hope you find employment soon if you haven't already. If you lived in or near Richmond, VA I might be able to help you find a programming job. Thanks again
hazlehurstga
 
If you can't find me a job...how about giving me a star instead! This forum is my part-time job without pay...

[wavey2]

VBSlammer
redinvader3walking.gif

Unemployed in Houston, Texas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top