If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Problem with Option in a Frame

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-13-07, 06:42
JimFourleaf78 JimFourleaf78 is offline
Registered User
 
Join Date: Nov 2007
Posts: 11
Problem with Option in a Frame

Hi,

I am having quite alot of trouble trying to place a set of radios inside a Frame object. Can anybody help me?

Dim MyChk Control

With UserForm1.Controls.Add("Forms.Frame.1", "frmQuestion")
.Caption = "TEST"
.Top = questionsTop
.Left = r * 26 - 16 + 20
.Width = 400
End With

Set MyChk = .frmQuestion.Controls.Add("Forms.OptionButton.1")MyChk.GroupNa me = "q_1"
MyChk.Value = 1
MyChk.Left = 20
Chk.Top = 20

Error is at .frmQuestion
Invalid or unqualified reference


What does this mean?
Reply With Quote
  #2 (permalink)  
Old 11-13-07, 07:41
MikeTheBike MikeTheBike is offline
Registered User
 
Join Date: Apr 2004
Location: Derbyshire, UK
Posts: 714
Hi

Never used dynamic control addition, but have you tried

Set MyChk = UserForm1.frmQuestion.Controls.Add("Forms.OptionBu tton.1")MyChk.GroupNa me = "q_1"

OR if the code is in UserForm1 perhaps this (without the period)

Set MyChk = frmQuestion.Controls.Add("Forms.OptionButton.1")My Chk.GroupNa me = "q_1"

You cannot use .frmQuestion without a 'With' statement such as

With UserForm1
OR
With Me

??

MTB
Reply With Quote
  #3 (permalink)  
Old 11-13-07, 09:49
JimFourleaf78 JimFourleaf78 is offline
Registered User
 
Join Date: Nov 2007
Posts: 11
Ah ok,

I have opted to do it this way and seems to work fine now.

With cFrame .Width = 560
.Top = questionsTop
.Left = 20
.ZOrder (1)
.Caption = "Question " & (n + 1)
End With

Set qLab = cFrame.Controls.Add("Forms.label.1", "lab", True)
With qLab
.Width = 450
.Height = 10
.Top = 5
.Left = 10
.ZOrder (0)
.Caption = CStr(rst(2))
End With

Set cControl2 = cFrame.Controls.Add("Forms.OptionButton.1", "opt1", True)
With cControl2
.GroupName = "q_" + CStr(rst(0))
.Width = 150
.Height = 20
.Top = 0
.Left = 475
.ZOrder (0)
.Value = 1
End With
Reply With Quote
  #4 (permalink)  
Old 11-13-07, 09:50
JimFourleaf78 JimFourleaf78 is offline
Registered User
 
Join Date: Nov 2007
Posts: 11
Sorry forgot to add this at the top

Set cFrame = Me.Controls.Add("Forms.Frame.1", "MyFrame", True)

many thanks
Reply With Quote
  #5 (permalink)  
Old 11-13-07, 11:30
JimFourleaf78 JimFourleaf78 is offline
Registered User
 
Join Date: Nov 2007
Posts: 11
I am having problems trying to associate an event (ie the onclick of the optionButtons) of these on the fly controls.

Can someone explain to me how this done?
Reply With Quote
  #6 (permalink)  
Old 11-13-07, 12:34
norie norie is offline
Registered User
 
Join Date: Mar 2006
Posts: 163
Jim

Can I ask what you are actually trying to achieve?

Why are you creating these controls on the fly?

It is possible to associate code with the controls events, what you would need would be a class module.

I don't actually have anything at hand that deals with controls on frames.

And I'm not sure if the click event of the option buttons will be exposed in a class module.
Reply With Quote
  #7 (permalink)  
Old 11-13-07, 14:06
JimFourleaf78 JimFourleaf78 is offline
Registered User
 
Join Date: Nov 2007
Posts: 11
Hi,

I seem to have almost solved the problem I had.

I am trying to generate a offline Questionnaire form which is a series of surveys that contain questions with sub parts. Hence I need to loop through a db recordset to get back my questions and generate a form with all of the controls on it.

The problem I face is generating them dynamically and then validating them.

This code seems to work fine until it is placed within a recordset loop

'code on my userform is named UserForm1:

Code:
Option Explicit
   
  Dim OB_Coll As Collection
  Dim Pos As Integer
   
  Private Sub cmdEvent_Click()
       Dim o As MSForms.OptionButton
       Dim OBE As New OptionButtonEvents
      '
       If OB_Coll Is Nothing Then Set OB_Coll = New Collection
       
        Set o = Me.Controls.Add("Forms.OptionButton.1", , True)
       o.Caption = "Dynamically Added Option Button" & CStr(Me.Controls.Count) - 2
       o.AutoSize = True
        o.Top = Pos
       OB_Coll.Add OBE
       Call OBE.WatchControl(o, Me)
       Pos = Pos + o.Height + 4
       
       
  End Sub

  Friend Sub OptionButtonDblClick(o As MSForms.OptionButton)
       MsgBox o.Name & " was just double-clicked..."
  End Sub
'code on a new class module named OptionButtonEvents
Code:
Option Explicit
   
  Private WithEvents ob As MSForms.OptionButton
  Private CallBackParent As UserForm1
   
  Private Sub ob_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
       Call CallBackParent.OptionButtonDblClick(ob)
  End Sub
   
  Friend Sub WatchControl(oControl As MSForms.OptionButton, oParent As UserForm1)
       Set ob = oControl
       Set CallBackParent = oParent
  End Sub
Can anybody tell me what I would need to do to get it working in a loop.
Would I have to use the EVAL function?
Reply With Quote
  #8 (permalink)  
Old 11-13-07, 14:29
norie norie is offline
Registered User
 
Join Date: Mar 2006
Posts: 163
Couldn't you just use listboxes?
Reply With Quote
  #9 (permalink)  
Old 11-14-07, 03:41
JimFourleaf78 JimFourleaf78 is offline
Registered User
 
Join Date: Nov 2007
Posts: 11
Its a possibility but I would prefer to use optionButtons as it resembles the website version.

If I was generating list boxes on the fly wouldnt I have the same problem trying to call an event to that object?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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