Re: Checking Options in UserForms Collection
- From: "monir" <monir@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 10 May 2005 19:08:04 -0700
Vasant;
Thank you for your suggestion and the sample code, which make sense and I'll
try to adapt it.
The difficulty here is that, although the form has currently 4 frames (with
many interrelated options disabled for now), it is likely that when the form
is complete, the number of frames would likely be 12, and all option buttons
would be enabled in a progressive fashion. Just in case you wonder, this
User Form is for my own use; a means of collecting my analytical research
over the years.
Now, wouldn't you agree that if a selection is missing in a particular
frame, you would want the focus to be shifted to one of its option buttons ??
The sample code layout I provided in my latest reply works fine. It is only
when I add:
myOption.SetFocus
after the MsgBox in the standard module macro:
Sub CheckOptions (myForm As UserForm)
that the "Run-time error '91'" appears.
myOption is declared As Control, but VBA doesn't like the statement:
myOption.SetFocus ?? and refers to help on Set variable As Object!
Any suggestions on how to fix this myOption.SetFocus '91' error would be
greatly appreciated.
"Vasant Nanavati" wrote:
> I haven't followed this whole discussion, but all you need to do is count
> the total number of checked option buttons and see if it matches the total
> number of frames.
>
> I posted this a long time ago to solve a similar problem; perhaps you can
> adapt it to your needs:
>
> Private Sub cmdOK_Click()
> Dim ctl As Control, i As Integer
> i = 0
> For Each ctl In Me.Controls
> If TypeOf ctl Is msforms.OptionButton Then
> If ctl Then
> i = i + 1
> End If
> End If
> Next
> If i = 4 Then 'no. of frames
> MsgBox "Run my code!"
> Unload Me
> Else
> MsgBox "Every frame must have a selected option button!"
> End If
> End Sub
>
> --
>
> Vasant
>
>
>
> "monir" <monir@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:6C2CC01D-6DBB-4DE8-BC44-C79EEDEFBACF@xxxxxxxxxxxxxxxx
> > This layout version of the code works almost perfectly!
> >
> > ' in the User Form's code *** : frmOptSelect
> > Private Sub btnOpen_Click ()
> > ...............................................
> > CheckOptions Me 'notice the argument Me
> > ..............................................
> > End Sub
> >
> > ' in a standard module
> > Sub CheckOptions (myForm As UserForm)
> > Dim myOption As Control
> > Dim myFlag As Integer
> > .....................................................
> > ' check if an option is selected in frame grpSeries (among the frame
> enabled
> > options)
> > For Each myOption In myForm.grpSeries.Controls
> > .....If myOption.Enabled = True Then
> > ............If myOption.Value = True Then myFlag = 1
> > .....End If
> > Next myOption
> > If myFlage <> 1 Then MsgBox "Select B- or GEL-Series" : myOption.SetFocus
> > ......................................................
> > ' repeat for all frames on the form
> > ......................................................
> > End Sub
> >
> > The message box prompt now displays, but followed by:
> > ......"Run-time error '91': Object variable or With block variable not
> set"
> > and myOption.SetFocus statement is highlighted.
> >
> > How to Set the control variable myOption?
> >
> > Thanks again.
> >
> >
> >
> > "monir" wrote:
> >
> > > Partick;
> > >
> > > There are 2 reasons (I thought) for having a separate macro code for the
> task:
> > > 1. it makes the form's code neater, specially if other frames are added
> > > later to the form and their options need to be similarly cheked; and
> > > 2. in the case of multiple user forms, only the standard module's code
> > > needs to be expanded
> > >
> > > Now, if you meant to place the regular macro in the form's code ***,
> not
> > > just the macro's code, then here it is. I moved the macro Sub
> CheckOptions
> > > () to the form's code ***, and replaced UserForms(1) reference by Me
> (and
> > > later by nothing).
> > > Clicking the btnOpen button, which has the call to the CheckOptions
> macro
> > > (as illustrated below), does not produce run-time errors, and does not
> > > display the MsgBox message!! Stepping into the macro suggests that the
> > > message should be displayed !
> > > Maybe I should follow the MsgBox statement by SetFocous on the relevant
> > > option! or maybe not ! Is it the regular macro in the Class-Module
> Forms
> > > code *** that is causing all these troubles ?
> > >
> > > Here is the latest attempt, with all macros in the form's code ***:
> > > frmOptSelect
> > >
> > > Private Sub btnOpen_Click ()
> > > ...............................................
> > > CheckOptions
> > > ..............................................
> > > End Sub
> > >
> > > Sub CheckOptions()
> > > Dim myOption As Control
> > > Dim myFlag As Integer
> > > .....................................................
> > > ' check options in frame grpSeries
> > > For Each myOption In Me.grpSeries.Controls
> > > .....If myOption.Value = True Then myFlag = 1
> > > Next myOption
> > > If myFlage <> 1 Then MsgBox "Select B- or GEL-Series"
> > > ......................................................
> > > ' repeat for all frames
> > > ......................................................
> > >
> > > Other suggestions? Thank you.
> > >
> > >
> > >
> > > "Patrick Molloy" wrote:
> > >
> > > > I didn't realise that the code was in a module. I assumed that you'd
> used
> > > > the form's own code ***. Why don't you?
> > > >
> > > > "monir" <monir@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> > > > news:1032AD94-99F2-4683-86EF-06A0473AF553@xxxxxxxxxxxxxxxx
> > > > > In the For Each statement:
> > > > > ' check options in frame grpSeries
> > > > > ......For Each myOption In UserForms(1).grpSeries.Controls
> > > > >
> > > > > if I replace UserForms(1) by UserForm("frmOptSelect")
> > > > > now it is "Run-time error '13': Type mismatch", and the For Each
> statement
> > > > > is highlighted. (That is different from the earlier: "Run-time error
> '9':
> > > > > Subscript out of range" when I used the user form index.)
> > > > >
> > > > > Does this reveal anything?
> > > > >
> > > > > Since I'm referring to the user form object in a standard macro,
> shouldn't
> > > > > the reference to the user form be specific either by index or by
> name ?
> > > > >
> > > > > Thanks again.
> > > > >
> > > > >
> > > > > "monir" wrote:
> > > > >
> > > > >> Patrick;
> > > > >>
> > > > >> Replacing UserForms(1). by Me. produced:
> > > > >> ........"Compile error: Invalid use of Me keyword"
> > > > >>
> > > > >> Another suggestion? Thank you.
> > > > >>
> > > > >>
> > > > >>
> > > > >> "Patrick Molloy" wrote:
> > > > >>
> > > > >> > probably zero basedinstead of
> > > > >> > UserForms(1).
> > > > >> > try
> > > > >> > me.
> > > > >> >
> > > > >> >
> > > > >> >
> > > > >> >
> > > > >> > "monir" wrote:
> > > > >> >
> > > > >> > > Hi;
> > > > >> > >
> > > > >> > > The user form, frmOptSelect, has a number of frames, each with
> a
> > > > >> > > number of
> > > > >> > > option controls. The algoritms for all combinations of options
> are
> > > > >> > > not
> > > > >> > > currently available, so I'm disabling certain options for now.
> > > > >> > > I'm trying to make sure that an option is selected in each
> frame on
> > > > >> > > the form
> > > > >> > > before I click the btnOpen button. In:
> > > > >> > >
> > > > >> > > Private Sub btnOpen_Click () event procedure and right at the
> top,
> > > > >> > > I
> > > > >> > > inserted:
> > > > >> > > ....... CheckOptions
> > > > >> > > which is a regular macro:
> > > > >> > >
> > > > >> > > Sub CheckOptions()
> > > > >> > > Dim myOption As Control
> > > > >> > > Dim myFlag As Integer
> > > > >> > > .....................................................
> > > > >> > > ' check options in frame grpSeries
> > > > >> > > For Each myOption In UserForms(1).grpSeries.Controls
> > > > >> > > .....If myOption.Value = True Then myFlag = 1
> > > > >> > > Next myOption
> > > > >> > > If myFlage <> 1 Then MsgBox "Select B- or GEL-Series"
> > > > >> > > ......................................................
> > > > >> > > ' repeat for all frames
> > > > >> > > ......................................................
> > > > >> > >
> > > > >> > > I got " Run-time error '9': Subscript out of range", and the
> above
> > > > >> > > For Each
> > > > >> > > statement is higlighted!
> > > > >> > >
> > > > >> > > Any suggestions ? Thank you
> > > >
> > > >
> > > >
>
>
>
.
- Follow-Ups:
- Re: Checking Options in UserForms Collection
- From: Vasant Nanavati
- Re: Checking Options in UserForms Collection
- References:
- Checking Options in UserForms Collection
- From: monir
- RE: Checking Options in UserForms Collection
- From: Patrick Molloy
- RE: Checking Options in UserForms Collection
- From: monir
- RE: Checking Options in UserForms Collection
- From: monir
- Re: Checking Options in UserForms Collection
- From: Patrick Molloy
- Re: Checking Options in UserForms Collection
- From: monir
- Re: Checking Options in UserForms Collection
- From: monir
- Re: Checking Options in UserForms Collection
- From: Vasant Nanavati
- Checking Options in UserForms Collection
- Prev by Date: Populating fields based on previous column values
- Next by Date: Re: Transfer data from sheet1 to sheet2
- Previous by thread: Re: Checking Options in UserForms Collection
- Next by thread: Re: Checking Options in UserForms Collection
- Index(es):