Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 215
Default Checking Options in UserForms Collection

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Checking Options in UserForms Collection

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 215
Default Checking Options in UserForms Collection

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 215
Default Checking Options in UserForms Collection

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Checking Options in UserForms Collection

I didn't realise that the code was in a module. I assumed that you'd used
the form's own code sheet. Why don't you?

"monir" wrote in message
...
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





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 215
Default Checking Options in UserForms Collection

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 sheet, not
just the macro's code, then here it is. I moved the macro Sub CheckOptions
() to the form's code sheet, 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 sheet that is causing all these troubles ?

Here is the latest attempt, with all macros in the form's code sheet:
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 sheet. Why don't you?

"monir" wrote in message
...
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




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 215
Default Checking Options in UserForms Collection

This layout version of the code works almost perfectly!

' in the User Form's code sheet : 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 sheet, not
just the macro's code, then here it is. I moved the macro Sub CheckOptions
() to the form's code sheet, 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 sheet that is causing all these troubles ?

Here is the latest attempt, with all macros in the form's code sheet:
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 sheet. Why don't you?

"monir" wrote in message
...
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




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Checking Options in UserForms Collection

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" wrote in message
...
This layout version of the code works almost perfectly!

' in the User Form's code sheet : 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 sheet,

not
just the macro's code, then here it is. I moved the macro Sub

CheckOptions
() to the form's code sheet, 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 sheet that is causing all these troubles ?

Here is the latest attempt, with all macros in the form's code sheet:
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 sheet. Why don't you?

"monir" wrote in message
...
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





  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 215
Default Checking Options in UserForms Collection

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" wrote in message
...
This layout version of the code works almost perfectly!

' in the User Form's code sheet : 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 sheet,

not
just the macro's code, then here it is. I moved the macro Sub

CheckOptions
() to the form's code sheet, 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 sheet that is causing all these troubles ?

Here is the latest attempt, with all macros in the form's code sheet:
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 sheet. Why don't you?

"monir" wrote in message
...
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






  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Checking Options in UserForms Collection

"monir" wrote in message
...
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

??

Not necessarily. But try:

myForm.grpSeries.Controls(0).SetFocus

(myOption goes out of scope after the loop.)

--

Vasant





  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 215
Default Checking Options in UserForms Collection

Vasant;
I replaced the myOption.SetFocus with your statement. The sample code
layout now looks like this:

' in the user form code's sheet frmOptSelect
Private Sub btnOpen_Click()
' before running the relevant programs, make sure that an option is selected
in each
' of the ?? frames on the form
CheckOptions Me ' notice the Me argument
.................................................. .............................
' open files and run my programs
.................................................. .............................
Unload Me
End Sub

' in a standard module
Sub CheckOptions(myForm As UserForm)
''to check that an option is selected in each of the ?? frames before
opening and running my relevant prgrams
' check ONLY among the enabled option controls within each frame
Dim myOption As Control
Dim myFlag As Integer
Dim CkeckBox
.................................................. ...........................................
myFlag = 0
' 3rd frame
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then
If myOption.Value = True Then myFlag = 3
End If
Next myOption
If myFlag < 3 Then
CheckBox = MsgBox("You haven't selected Inflow Type!!" & Chr(13) &
"Select now ?", vbYesNo, "User Form Opt Prop Select")
If CheckBox = vbYes Then myForm.grpInflow.Controls(0).SetFocus
End If
.................................................. .........................................
' repeat for each frame on the form
.................................................. .........................................
End Sub

The above changes to SetFocus method produced a different error:
..........."Run-time error '2110': Can't move focus to the control because
it is invisible, not enabled, or of the type that does not accept focus"

Could the error be associated with the index 0 of Controls ?
Any number of option controls and in any sequence in a particular frame
under a particular scenario may be disabled.

Thanks again.



"Vasant Nanavati" wrote:

"monir" wrote in message
...
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

??

Not necessarily. But try:

myForm.grpSeries.Controls(0).SetFocus

(myOption goes out of scope after the loop.)

--

Vasant




  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 215
Default Checking Options in UserForms Collection

Follow-up to my latest reply:

Could it be that the SetFocus method does not apply to User Form option
controls ??
But I tried Click earlier. It didn't work either!!



"monir" wrote:

Vasant;
I replaced the myOption.SetFocus with your statement. The sample code
layout now looks like this:

' in the user form code's sheet frmOptSelect
Private Sub btnOpen_Click()
' before running the relevant programs, make sure that an option is selected
in each
' of the ?? frames on the form
CheckOptions Me ' notice the Me argument
.................................................. ............................
' open files and run my programs
.................................................. ............................
Unload Me
End Sub

' in a standard module
Sub CheckOptions(myForm As UserForm)
''to check that an option is selected in each of the ?? frames before
opening and running my relevant prgrams
' check ONLY among the enabled option controls within each frame
Dim myOption As Control
Dim myFlag As Integer
Dim CkeckBox
.................................................. .........................................
myFlag = 0
' 3rd frame
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then
If myOption.Value = True Then myFlag = 3
End If
Next myOption
If myFlag < 3 Then
CheckBox = MsgBox("You haven't selected Inflow Type!!" & Chr(13) &
"Select now ?", vbYesNo, "User Form Opt Prop Select")
If CheckBox = vbYes Then myForm.grpInflow.Controls(0).SetFocus
End If
.................................................. .......................................
' repeat for each frame on the form
.................................................. .......................................
End Sub

The above changes to SetFocus method produced a different error:
.........."Run-time error '2110': Can't move focus to the control because
it is invisible, not enabled, or of the type that does not accept focus"

Could the error be associated with the index 0 of Controls ?
Any number of option controls and in any sequence in a particular frame
under a particular scenario may be disabled.

Thanks again.



"Vasant Nanavati" wrote:

"monir" wrote in message
...
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

??

Not necessarily. But try:

myForm.grpSeries.Controls(0).SetFocus

(myOption goes out of scope after the loop.)

--

Vasant




  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Checking Options in UserForms Collection

Hi Monir:

Of course, if the first option button is disabled, it cannot accept the
focus. In that case, you have to loop through the option buttons in the
frame again, find the first one that is not disabled, and set the focus to
it.

Regards,

Vasant

"monir" wrote in message
...
Vasant;
I replaced the myOption.SetFocus with your statement. The sample code
layout now looks like this:

' in the user form code's sheet frmOptSelect
Private Sub btnOpen_Click()
' before running the relevant programs, make sure that an option is

selected
in each
' of the ?? frames on the form
CheckOptions Me ' notice the Me argument

.................................................. ...........................
...
' open files and run my programs

.................................................. ...........................
...
Unload Me
End Sub

' in a standard module
Sub CheckOptions(myForm As UserForm)
''to check that an option is selected in each of the ?? frames before
opening and running my relevant prgrams
' check ONLY among the enabled option controls within each frame
Dim myOption As Control
Dim myFlag As Integer
Dim CkeckBox

.................................................. ...........................
................
myFlag = 0
' 3rd frame
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then
If myOption.Value = True Then myFlag = 3
End If
Next myOption
If myFlag < 3 Then
CheckBox = MsgBox("You haven't selected Inflow Type!!" & Chr(13) &
"Select now ?", vbYesNo, "User Form Opt Prop Select")
If CheckBox = vbYes Then myForm.grpInflow.Controls(0).SetFocus
End If

.................................................. ...........................
..............
' repeat for each frame on the form

.................................................. ...........................
..............
End Sub

The above changes to SetFocus method produced a different error:
.........."Run-time error '2110': Can't move focus to the control because
it is invisible, not enabled, or of the type that does not accept focus"

Could the error be associated with the index 0 of Controls ?
Any number of option controls and in any sequence in a particular frame
under a particular scenario may be disabled.

Thanks again.



"Vasant Nanavati" wrote:

"monir" wrote in message
...
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
??

Not necessarily. But try:

myForm.grpSeries.Controls(0).SetFocus

(myOption goes out of scope after the loop.)

--

Vasant






  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 215
Default Checking Options in UserForms Collection

Hi Vasant;

I've implemented your latest suggestion. VBA stll does not like the
SetFocus statemet!

Here is the latest sample code:
------------------------------------------------------------------
' in the user form code's sheet frmOptSelect
Private Sub btnOpen_Click()
' before running the relevant programs, make sure that an option is selected
in each
' of the ?? frames on the form
'................................................. .............
CheckOptions Me ' notice the Me argument
'................................................. .............
' open files and run my programs
'................................................. .............
Unload Me
End Sub
------------------------------------------------------------------
' in a standard module
Sub CheckOptions(myForm As UserForm)
Dim myOption As Control
Dim myFlag As Integer
Dim CkeckBox
'................................................. .............
myFlag = 0
' 3rd frame
' make sure an option is selected among the enabled options on this frame
' grpInflow, otherwise display a message and set focus to the 1st enabled
option on
' this frame
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then
If myOption.Value = True Then myFlag = 3
End If
Next myOption
If myFlag < 3 Then
CheckBox = MsgBox("You haven't selected Inflow Type!!" & Chr(13) & _
"Select now ?", vbYesNo, "User Form Opt Prop
Select")
' set focus on the 1st enabled option control button on this frame
If CheckBox = vbYes Then
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then
myForm.grpInflow.Controls(0).SetFocus ' problem
!!!!!!!!!!!!!
Exit Sub
End If
Next myOption
End If
End If
'................................................. .............
' repeat for each frame on the form
'................................................. .............
End Sub
------------------------------------------------------------------

The above changes produced the same error:
..........."Run-time error '2110': Can't move focus to the control because
it is invisible, not enabled, or of the type that does not accept focus"
and the SetFocus statement is highlighted!

I apologize for the untidiness of the above sample code, but my concern
right now is to get the SetFocus method working properly!

Any suggestions ? Thank you.




"Vasant Nanavati" wrote:

Hi Monir:

Of course, if the first option button is disabled, it cannot accept the
focus. In that case, you have to loop through the option buttons in the
frame again, find the first one that is not disabled, and set the focus to
it.

Regards,

Vasant

"monir" wrote in message
...
Vasant;
I replaced the myOption.SetFocus with your statement. The sample code
layout now looks like this:

' in the user form code's sheet frmOptSelect
Private Sub btnOpen_Click()
' before running the relevant programs, make sure that an option is

selected
in each
' of the ?? frames on the form
CheckOptions Me ' notice the Me argument

.................................................. ...........................
...
' open files and run my programs

.................................................. ...........................
...
Unload Me
End Sub

' in a standard module
Sub CheckOptions(myForm As UserForm)
''to check that an option is selected in each of the ?? frames before
opening and running my relevant prgrams
' check ONLY among the enabled option controls within each frame
Dim myOption As Control
Dim myFlag As Integer
Dim CkeckBox

.................................................. ...........................
................
myFlag = 0
' 3rd frame
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then
If myOption.Value = True Then myFlag = 3
End If
Next myOption
If myFlag < 3 Then
CheckBox = MsgBox("You haven't selected Inflow Type!!" & Chr(13) &
"Select now ?", vbYesNo, "User Form Opt Prop Select")
If CheckBox = vbYes Then myForm.grpInflow.Controls(0).SetFocus
End If

.................................................. ...........................
..............
' repeat for each frame on the form

.................................................. ...........................
..............
End Sub

The above changes to SetFocus method produced a different error:
.........."Run-time error '2110': Can't move focus to the control because
it is invisible, not enabled, or of the type that does not accept focus"

Could the error be associated with the index 0 of Controls ?
Any number of option controls and in any sequence in a particular frame
under a particular scenario may be disabled.

Thanks again.



"Vasant Nanavati" wrote:

"monir" wrote in message
...
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
??

Not necessarily. But try:

myForm.grpSeries.Controls(0).SetFocus

(myOption goes out of scope after the loop.)

--

Vasant







  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 215
Default Checking Options in UserForms Collection

Vasant;

Getting very close to solving the problem!

It appears that the SetFocus problem is confined to the 2nd For Each loop,
and more specifically to the IF structure that includes the SetFocus
statement. Here is why.

When I temporary modified the option controls interface such that the 1st
option control in the frame is enabled (but still no selection in the frame),
the code works fine and the focus is set correctly following the MsgBox
prompt!
But once the "1st enabled option button" is not the "1st option button" in
the frame, the code fails with the ......."Run-time error '2110': Can't move
focus to the control because it is invisible, not enabled, or of the type
that does not accept focus" and
the SetFocus statement is highlighted!

What did I do wrong !! Here is that section of the sample code:

'................................................. ........
'................................................. ........
' 3rd frame
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then 'check only among the enabled options
If myOption.Value = True Then myFlag = 3
End If
Next myOption
If myFlag < 3 Then ' a selection is missing in this frame.
' First display a message and then set focus on the 1st enabled option
control on
' this frame
MissingSelection = True
CheckBox = MsgBox("You haven't ... " & Chr(13) & ".. now ?",
vbYesNo, "..")
If CheckBox = vbYes Then 'now SetFocus on the 1st enabled option
control
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then
myForm.grpInflow.Controls(0).SetFocus
Exit Sub
End If
Next myOption
End If
End If

Regards.



"monir" wrote:

Hi Vasant;

I've implemented your latest suggestion. VBA stll does not like the
SetFocus statemet!

Here is the latest sample code:
------------------------------------------------------------------
' in the user form code's sheet frmOptSelect
Private Sub btnOpen_Click()
' before running the relevant programs, make sure that an option is selected
in each
' of the ?? frames on the form
'................................................. .............
CheckOptions Me ' notice the Me argument
'................................................. .............
' open files and run my programs
'................................................. .............
Unload Me
End Sub
------------------------------------------------------------------
' in a standard module
Sub CheckOptions(myForm As UserForm)
Dim myOption As Control
Dim myFlag As Integer
Dim CkeckBox
'................................................. .............
myFlag = 0
' 3rd frame
' make sure an option is selected among the enabled options on this frame
' grpInflow, otherwise display a message and set focus to the 1st enabled
option on
' this frame
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then
If myOption.Value = True Then myFlag = 3
End If
Next myOption
If myFlag < 3 Then
CheckBox = MsgBox("You haven't selected Inflow Type!!" & Chr(13) & _
"Select now ?", vbYesNo, "User Form Opt Prop
Select")
' set focus on the 1st enabled option control button on this frame
If CheckBox = vbYes Then
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then
myForm.grpInflow.Controls(0).SetFocus ' problem
!!!!!!!!!!!!!
Exit Sub
End If
Next myOption
End If
End If
'................................................. .............
' repeat for each frame on the form
'................................................. .............
End Sub
------------------------------------------------------------------

The above changes produced the same error:
.........."Run-time error '2110': Can't move focus to the control because
it is invisible, not enabled, or of the type that does not accept focus"
and the SetFocus statement is highlighted!

I apologize for the untidiness of the above sample code, but my concern
right now is to get the SetFocus method working properly!

Any suggestions ? Thank you.




"Vasant Nanavati" wrote:

Hi Monir:

Of course, if the first option button is disabled, it cannot accept the
focus. In that case, you have to loop through the option buttons in the
frame again, find the first one that is not disabled, and set the focus to
it.

Regards,

Vasant

"monir" wrote in message
...
Vasant;
I replaced the myOption.SetFocus with your statement. The sample code
layout now looks like this:

' in the user form code's sheet frmOptSelect
Private Sub btnOpen_Click()
' before running the relevant programs, make sure that an option is

selected
in each
' of the ?? frames on the form
CheckOptions Me ' notice the Me argument

.................................................. ...........................
...
' open files and run my programs

.................................................. ...........................
...
Unload Me
End Sub

' in a standard module
Sub CheckOptions(myForm As UserForm)
''to check that an option is selected in each of the ?? frames before
opening and running my relevant prgrams
' check ONLY among the enabled option controls within each frame
Dim myOption As Control
Dim myFlag As Integer
Dim CkeckBox

.................................................. ...........................
................
myFlag = 0
' 3rd frame
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then
If myOption.Value = True Then myFlag = 3
End If
Next myOption
If myFlag < 3 Then
CheckBox = MsgBox("You haven't selected Inflow Type!!" & Chr(13) &
"Select now ?", vbYesNo, "User Form Opt Prop Select")
If CheckBox = vbYes Then myForm.grpInflow.Controls(0).SetFocus
End If

.................................................. ...........................
..............
' repeat for each frame on the form

.................................................. ...........................
..............
End Sub

The above changes to SetFocus method produced a different error:
.........."Run-time error '2110': Can't move focus to the control because
it is invisible, not enabled, or of the type that does not accept focus"

Could the error be associated with the index 0 of Controls ?
Any number of option controls and in any sequence in a particular frame
under a particular scenario may be disabled.

Thanks again.



"Vasant Nanavati" wrote:

"monir" wrote in message
...
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
??

Not necessarily. But try:

myForm.grpSeries.Controls(0).SetFocus

(myOption goes out of scope after the loop.)

--

Vasant









  #16   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 215
Default Checking Options in UserForms Collection

Hi Vasant;
(I've just posted a reply, but it appears to have been lost! Here is a
recompilation to the best of my recollection)

Here is the solution to the SetFocus problem (arrived at by trial and error):

Replace : .... myForm.grpInflow.Controls(0).SetFocus
by : .... myOption.SetFocus

Why this works and the other doesn't, I don't have a clue!

The sample code now looks like :

'------------------------------------------------------------------
' in the user form code's sheet frmOptSelect
Private Sub btnOpen_Click()
' before opening and running the relevant programs, make sure that an option
is
' selected in each frame on the form

Dim MissingOption As Boolean

Call CheckOptions (Me, MissingOption)
If MissingOption = True Then Exit Sub
'
'................................................. .............
' open files and run my programs
'................................................. .............
Unload Me
End Sub

'------------------------------------------------------------------
' in a standard module
Sub CheckOptions(myForm As UserForm, MissingSelection)
' to check that an option is selected in each of the ?? frames before
opening and
' running the relevant optimum selection programs
' check ONLY among the enabled options within each frame

Dim myOption As Control
Dim myFlag As Integer, myIndex As Integer
Dim CkeckBox
Dim myFrame As Frame

For myIndex = 3 To 3 'testing frame 3 only
MissingSelection = False
myFlag =
'................................................. ...............................................
'................................................. ................................................
' 3rd frame
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then 'check only among the enabled
options ...
If myOption.Value = True Then myFlag = myIndex
End If
Next myOption
If myFlag < myIndex Then ' selection is missing in this frame
' first display a message and then, if the answer is Yes, set focus on the 1st
' enabled option control in this frame
MissingSelection = True
CheckBox = MsgBox("You ... Inflow !!" & Chr(13) & "..Now?", vbYesNo,
"...")
If CheckBox = vbYes Then 'now Set Focus on the 1st enabled option
control ..
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then myOption.SetFocus: Exit Sub
Next myOption
End If
End If
Next myInde
'................................................. ...............................................
'................................................. ................................................
End Sub
'------------------------------------------------------------------

Now, instead of repeating the above section of the CheckOptions() macro code
4 times (or 12 times as the case may be, one for each frame), how about:
a) declare myFrame As Frame (done above)
b) replace : For myIndex = 3 To 3
by, say : For myIndex = 1 To 4 '4 frames for now
c) followed by assigning one of the 4 frames' names to myFrame :
myFrame = Choose (myIndex,grpSeries,grpPropArrg,grpInflow,grpPerfor m)

(This is certainly quicker / easier than creating an array, but I
suspect it wouldn't
work! Normally, the Choose function returns a selection from a list
of values or
expressions, not a frame name! Any insight ? or suggestions ?)
d) replace the frame name grpInflow in the above sample code by myFrame

Does the above make sense to you ?
Your help has been greatly apprerciated.
Regards.


"monir" wrote:

Vasant;

Getting very close to solving the problem!

It appears that the SetFocus problem is confined to the 2nd For Each loop,
and more specifically to the IF structure that includes the SetFocus
statement. Here is why.

When I temporary modified the option controls interface such that the 1st
option control in the frame is enabled (but still no selection in the frame),
the code works fine and the focus is set correctly following the MsgBox
prompt!
But once the "1st enabled option button" is not the "1st option button" in
the frame, the code fails with the ......."Run-time error '2110': Can't move
focus to the control because it is invisible, not enabled, or of the type
that does not accept focus" and
the SetFocus statement is highlighted!

What did I do wrong !! Here is that section of the sample code:

'................................................. ........
'................................................. ........
' 3rd frame
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then 'check only among the enabled options
If myOption.Value = True Then myFlag = 3
End If
Next myOption
If myFlag < 3 Then ' a selection is missing in this frame.
' First display a message and then set focus on the 1st enabled option
control on
' this frame
MissingSelection = True
CheckBox = MsgBox("You haven't ... " & Chr(13) & ".. now ?",
vbYesNo, "..")
If CheckBox = vbYes Then 'now SetFocus on the 1st enabled option
control
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then
myForm.grpInflow.Controls(0).SetFocus
Exit Sub
End If
Next myOption
End If
End If

Regards.



"monir" wrote:

Hi Vasant;

I've implemented your latest suggestion. VBA stll does not like the
SetFocus statemet!

Here is the latest sample code:
------------------------------------------------------------------
' in the user form code's sheet frmOptSelect
Private Sub btnOpen_Click()
' before running the relevant programs, make sure that an option is selected
in each
' of the ?? frames on the form
'................................................. .............
CheckOptions Me ' notice the Me argument
'................................................. .............
' open files and run my programs
'................................................. .............
Unload Me
End Sub
------------------------------------------------------------------
' in a standard module
Sub CheckOptions(myForm As UserForm)
Dim myOption As Control
Dim myFlag As Integer
Dim CkeckBox
'................................................. .............
myFlag = 0
' 3rd frame
' make sure an option is selected among the enabled options on this frame
' grpInflow, otherwise display a message and set focus to the 1st enabled
option on
' this frame
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then
If myOption.Value = True Then myFlag = 3
End If
Next myOption
If myFlag < 3 Then
CheckBox = MsgBox("You haven't selected Inflow Type!!" & Chr(13) & _
"Select now ?", vbYesNo, "User Form Opt Prop
Select")
' set focus on the 1st enabled option control button on this frame
If CheckBox = vbYes Then
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then
myForm.grpInflow.Controls(0).SetFocus ' problem
!!!!!!!!!!!!!
Exit Sub
End If
Next myOption
End If
End If
'................................................. .............
' repeat for each frame on the form
'................................................. .............
End Sub
------------------------------------------------------------------

The above changes produced the same error:
.........."Run-time error '2110': Can't move focus to the control because
it is invisible, not enabled, or of the type that does not accept focus"
and the SetFocus statement is highlighted!

I apologize for the untidiness of the above sample code, but my concern
right now is to get the SetFocus method working properly!

Any suggestions ? Thank you.




"Vasant Nanavati" wrote:

Hi Monir:

Of course, if the first option button is disabled, it cannot accept the
focus. In that case, you have to loop through the option buttons in the
frame again, find the first one that is not disabled, and set the focus to
it.

Regards,

Vasant

"monir" wrote in message
...
Vasant;
I replaced the myOption.SetFocus with your statement. The sample code
layout now looks like this:

' in the user form code's sheet frmOptSelect
Private Sub btnOpen_Click()
' before running the relevant programs, make sure that an option is
selected
in each
' of the ?? frames on the form
CheckOptions Me ' notice the Me argument

.................................................. ...........................
...
' open files and run my programs

.................................................. ...........................
...
Unload Me
End Sub

' in a standard module
Sub CheckOptions(myForm As UserForm)
''to check that an option is selected in each of the ?? frames before
opening and running my relevant prgrams
' check ONLY among the enabled option controls within each frame
Dim myOption As Control
Dim myFlag As Integer
Dim CkeckBox

.................................................. ...........................
................
myFlag = 0
' 3rd frame
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then
If myOption.Value = True Then myFlag = 3
End If
Next myOption
If myFlag < 3 Then
CheckBox = MsgBox("You haven't selected Inflow Type!!" & Chr(13) &
"Select now ?", vbYesNo, "User Form Opt Prop Select")
If CheckBox = vbYes Then myForm.grpInflow.Controls(0).SetFocus
End If

.................................................. ...........................
..............
' repeat for each frame on the form

.................................................. ...........................
..............
End Sub

The above changes to SetFocus method produced a different error:
.........."Run-time error '2110': Can't move focus to the control because
it is invisible, not enabled, or of the type that does not accept focus"

Could the error be associated with the index 0 of Controls ?
Any number of option controls and in any sequence in a particular frame
under a particular scenario may be disabled.

Thanks again.



"Vasant Nanavati" wrote:

"monir" wrote in message
...
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
??

Not necessarily. But try:

myForm.grpSeries.Controls(0).SetFocus

(myOption goes out of scope after the loop.)

--

Vasant







  #17   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 215
Default Checking Options in UserForms Collection

Vasant;

Here are the answers to my latest suggestions:

a) use the keyword Set to assign values to the new frame object myFrame
b) the argument list of the Choose function must include reference to the
user form myForm
c) remove reference to myForm from the macro's subsequent code statements

The macro code, which now works perfectly, looks like:
--------------------------------------------------------------------------------
' in a standard module
Sub CheckOptions(myForm As UserForm, MissingSelection)

Dim myOption As Control
Dim myFlag As Integer, myIndex As Integer
Dim myFrame As Frame

For myIndex = 1 To 4 ' 4 frames on the form, named: grp1, grp2, grp3, grp4

Set myFrame = Choose (myIndex, myForm.grp1, myForm.grp2, myForm.grp3,
myForm.grp4)
MissingSelection = False ' no selection is missing
myFlag = 0
For Each myOption In myFrame.Controls
If myOption.Enabled = True Then
If myOption.Value = True Then myFlag = myIndex
End If
If myFlag < myIndex Then ' selection is missing in this frame.
MissingSelection = True
'.......myCheckBox ..........................
'.......SetFocus ................................
End If
Next myIndex
End Sub
--------------------------------------------------------------------------------

Thanks again for your help in solving the problem.


"monir" wrote:

Hi Vasant;
(I've just posted a reply, but it appears to have been lost! Here is a
recompilation to the best of my recollection)

Here is the solution to the SetFocus problem (arrived at by trial and error):

Replace : .... myForm.grpInflow.Controls(0).SetFocus
by : .... myOption.SetFocus

Why this works and the other doesn't, I don't have a clue!

The sample code now looks like :

'------------------------------------------------------------------
' in the user form code's sheet frmOptSelect
Private Sub btnOpen_Click()
' before opening and running the relevant programs, make sure that an option
is
' selected in each frame on the form

Dim MissingOption As Boolean

Call CheckOptions (Me, MissingOption)
If MissingOption = True Then Exit Sub
'
'................................................. .............
' open files and run my programs
'................................................. .............
Unload Me
End Sub

'------------------------------------------------------------------
' in a standard module
Sub CheckOptions(myForm As UserForm, MissingSelection)
' to check that an option is selected in each of the ?? frames before
opening and
' running the relevant optimum selection programs
' check ONLY among the enabled options within each frame

Dim myOption As Control
Dim myFlag As Integer, myIndex As Integer
Dim CkeckBox
Dim myFrame As Frame

For myIndex = 3 To 3 'testing frame 3 only
MissingSelection = False
myFlag = 0
'................................................. ................................................
'................................................. ................................................
' 3rd frame
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then 'check only among the enabled
options ...
If myOption.Value = True Then myFlag = myIndex
End If
Next myOption
If myFlag < myIndex Then ' selection is missing in this frame
' first display a message and then, if the answer is Yes, set focus on the 1st
' enabled option control in this frame
MissingSelection = True
CheckBox = MsgBox("You ... Inflow !!" & Chr(13) & "..Now?", vbYesNo,
"...")
If CheckBox = vbYes Then 'now Set Focus on the 1st enabled option
control ..
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then myOption.SetFocus: Exit Sub
Next myOption
End If
End If
Next myIndex
'................................................. ................................................
'................................................. ................................................
End Sub
'------------------------------------------------------------------

Now, instead of repeating the above section of the CheckOptions() macro code
4 times (or 12 times as the case may be, one for each frame), how about:
a) declare myFrame As Frame (done above)
b) replace : For myIndex = 3 To 3
by, say : For myIndex = 1 To 4 '4 frames for now
c) followed by assigning one of the 4 frames' names to myFrame :
myFrame = Choose (myIndex,grpSeries,grpPropArrg,grpInflow,grpPerfor m)

(This is certainly quicker / easier than creating an array, but I
suspect it wouldn't
work! Normally, the Choose function returns a selection from a list
of values or
expressions, not a frame name! Any insight ? or suggestions ?)
d) replace the frame name grpInflow in the above sample code by myFrame

Does the above make sense to you ?
Your help has been greatly apprerciated.
Regards.


"monir" wrote:

Vasant;

Getting very close to solving the problem!

It appears that the SetFocus problem is confined to the 2nd For Each loop,
and more specifically to the IF structure that includes the SetFocus
statement. Here is why.

When I temporary modified the option controls interface such that the 1st
option control in the frame is enabled (but still no selection in the frame),
the code works fine and the focus is set correctly following the MsgBox
prompt!
But once the "1st enabled option button" is not the "1st option button" in
the frame, the code fails with the ......."Run-time error '2110': Can't move
focus to the control because it is invisible, not enabled, or of the type
that does not accept focus" and
the SetFocus statement is highlighted!

What did I do wrong !! Here is that section of the sample code:

'................................................. ........
'................................................. ........
' 3rd frame
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then 'check only among the enabled options
If myOption.Value = True Then myFlag = 3
End If
Next myOption
If myFlag < 3 Then ' a selection is missing in this frame.
' First display a message and then set focus on the 1st enabled option
control on
' this frame
MissingSelection = True
CheckBox = MsgBox("You haven't ... " & Chr(13) & ".. now ?",
vbYesNo, "..")
If CheckBox = vbYes Then 'now SetFocus on the 1st enabled option
control
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then
myForm.grpInflow.Controls(0).SetFocus
Exit Sub
End If
Next myOption
End If
End If

Regards.



"monir" wrote:

Hi Vasant;

I've implemented your latest suggestion. VBA stll does not like the
SetFocus statemet!

Here is the latest sample code:
------------------------------------------------------------------
' in the user form code's sheet frmOptSelect
Private Sub btnOpen_Click()
' before running the relevant programs, make sure that an option is selected
in each
' of the ?? frames on the form
'................................................. .............
CheckOptions Me ' notice the Me argument
'................................................. .............
' open files and run my programs
'................................................. .............
Unload Me
End Sub
------------------------------------------------------------------
' in a standard module
Sub CheckOptions(myForm As UserForm)
Dim myOption As Control
Dim myFlag As Integer
Dim CkeckBox
'................................................. .............
myFlag = 0
' 3rd frame
' make sure an option is selected among the enabled options on this frame
' grpInflow, otherwise display a message and set focus to the 1st enabled
option on
' this frame
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then
If myOption.Value = True Then myFlag = 3
End If
Next myOption
If myFlag < 3 Then
CheckBox = MsgBox("You haven't selected Inflow Type!!" & Chr(13) & _
"Select now ?", vbYesNo, "User Form Opt Prop
Select")
' set focus on the 1st enabled option control button on this frame
If CheckBox = vbYes Then
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then
myForm.grpInflow.Controls(0).SetFocus ' problem
!!!!!!!!!!!!!
Exit Sub
End If
Next myOption
End If
End If
'................................................. .............
' repeat for each frame on the form
'................................................. .............
End Sub
------------------------------------------------------------------

The above changes produced the same error:
.........."Run-time error '2110': Can't move focus to the control because
it is invisible, not enabled, or of the type that does not accept focus"
and the SetFocus statement is highlighted!

I apologize for the untidiness of the above sample code, but my concern
right now is to get the SetFocus method working properly!

Any suggestions ? Thank you.




"Vasant Nanavati" wrote:

Hi Monir:

Of course, if the first option button is disabled, it cannot accept the
focus. In that case, you have to loop through the option buttons in the
frame again, find the first one that is not disabled, and set the focus to
it.

Regards,

Vasant

"monir" wrote in message
...
Vasant;
I replaced the myOption.SetFocus with your statement. The sample code
layout now looks like this:

' in the user form code's sheet frmOptSelect
Private Sub btnOpen_Click()
' before running the relevant programs, make sure that an option is
selected
in each
' of the ?? frames on the form
CheckOptions Me ' notice the Me argument

.................................................. ...........................
...
' open files and run my programs

.................................................. ...........................
...
Unload Me
End Sub

' in a standard module
Sub CheckOptions(myForm As UserForm)
''to check that an option is selected in each of the ?? frames before
opening and running my relevant prgrams
' check ONLY among the enabled option controls within each frame
Dim myOption As Control
Dim myFlag As Integer
Dim CkeckBox

.................................................. ...........................
................
myFlag = 0
' 3rd frame
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then
If myOption.Value = True Then myFlag = 3
End If
Next myOption
If myFlag < 3 Then
CheckBox = MsgBox("You haven't selected Inflow Type!!" & Chr(13) &
"Select now ?", vbYesNo, "User Form Opt Prop Select")
If CheckBox = vbYes Then myForm.grpInflow.Controls(0).SetFocus
End If

.................................................. ...........................
..............
' repeat for each frame on the form

.................................................. ...........................
..............
End Sub

The above changes to SetFocus method produced a different error:
.........."Run-time error '2110': Can't move focus to the control because
it is invisible, not enabled, or of the type that does not accept focus"

Could the error be associated with the index 0 of Controls ?
Any number of option controls and in any sequence in a particular frame
under a particular scenario may be disabled.

Thanks again.



"Vasant Nanavati" wrote:

"monir" wrote in message
...

  #18   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Checking Options in UserForms Collection

Sorry, Monir; I was traveling. Glad you got it to work!

--

Vasant

"monir" wrote in message
...
Vasant;

Here are the answers to my latest suggestions:

a) use the keyword Set to assign values to the new frame object myFrame
b) the argument list of the Choose function must include reference to the
user form myForm
c) remove reference to myForm from the macro's subsequent code statements

The macro code, which now works perfectly, looks like:
--------------------------------------------------------------------------

------
' in a standard module
Sub CheckOptions(myForm As UserForm, MissingSelection)

Dim myOption As Control
Dim myFlag As Integer, myIndex As Integer
Dim myFrame As Frame

For myIndex = 1 To 4 ' 4 frames on the form, named: grp1, grp2, grp3,

grp4

Set myFrame = Choose (myIndex, myForm.grp1, myForm.grp2, myForm.grp3,
myForm.grp4)
MissingSelection = False ' no selection is missing
myFlag = 0
For Each myOption In myFrame.Controls
If myOption.Enabled = True Then
If myOption.Value = True Then myFlag = myIndex
End If
If myFlag < myIndex Then ' selection is missing in this frame.
MissingSelection = True
'.......myCheckBox ..........................
'.......SetFocus ................................
End If
Next myIndex
End Sub
--------------------------------------------------------------------------

------

Thanks again for your help in solving the problem.


"monir" wrote:

Hi Vasant;
(I've just posted a reply, but it appears to have been lost! Here is a
recompilation to the best of my recollection)

Here is the solution to the SetFocus problem (arrived at by trial and

error):

Replace : .... myForm.grpInflow.Controls(0).SetFocus
by : .... myOption.SetFocus

Why this works and the other doesn't, I don't have a clue!

The sample code now looks like :

'------------------------------------------------------------------
' in the user form code's sheet frmOptSelect
Private Sub btnOpen_Click()
' before opening and running the relevant programs, make sure that an

option
is
' selected in each frame on the form

Dim MissingOption As Boolean

Call CheckOptions (Me, MissingOption)
If MissingOption = True Then Exit Sub
'
'................................................. .............
' open files and run my programs
'................................................. .............
Unload Me
End Sub

'------------------------------------------------------------------
' in a standard module
Sub CheckOptions(myForm As UserForm, MissingSelection)
' to check that an option is selected in each of the ?? frames before
opening and
' running the relevant optimum selection programs
' check ONLY among the enabled options within each frame

Dim myOption As Control
Dim myFlag As Integer, myIndex As Integer
Dim CkeckBox
Dim myFrame As Frame

For myIndex = 3 To 3 'testing frame 3 only
MissingSelection = False
myFlag = 0

'................................................. ..........................
.......................

'................................................. ..........................
.......................
' 3rd frame
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then 'check only among the enabled
options ...
If myOption.Value = True Then myFlag = myIndex
End If
Next myOption
If myFlag < myIndex Then ' selection is missing in this frame
' first display a message and then, if the answer is Yes, set focus on

the 1st
' enabled option control in this frame
MissingSelection = True
CheckBox = MsgBox("You ... Inflow !!" & Chr(13) & "..Now?",

vbYesNo,
"...")
If CheckBox = vbYes Then 'now Set Focus on the 1st enabled

option
control ..
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then myOption.SetFocus: Exit

Sub
Next myOption
End If
End If
Next myIndex

'................................................. ..........................
.......................

'................................................. ..........................
.......................
End Sub
'------------------------------------------------------------------

Now, instead of repeating the above section of the CheckOptions() macro

code
4 times (or 12 times as the case may be, one for each frame), how

about:
a) declare myFrame As Frame (done above)
b) replace : For myIndex = 3 To 3
by, say : For myIndex = 1 To 4 '4 frames for now
c) followed by assigning one of the 4 frames' names to myFrame :
myFrame = Choose

(myIndex,grpSeries,grpPropArrg,grpInflow,grpPerfor m)

(This is certainly quicker / easier than creating an array, but I
suspect it wouldn't
work! Normally, the Choose function returns a selection from a

list
of values or
expressions, not a frame name! Any insight ? or suggestions ?)
d) replace the frame name grpInflow in the above sample code by myFrame

Does the above make sense to you ?
Your help has been greatly apprerciated.
Regards.


"monir" wrote:

Vasant;

Getting very close to solving the problem!

It appears that the SetFocus problem is confined to the 2nd For Each

loop,
and more specifically to the IF structure that includes the SetFocus
statement. Here is why.

When I temporary modified the option controls interface such that the

1st
option control in the frame is enabled (but still no selection in the

frame),
the code works fine and the focus is set correctly following the

MsgBox
prompt!
But once the "1st enabled option button" is not the "1st option

button" in
the frame, the code fails with the ......."Run-time error '2110':

Can't move
focus to the control because it is invisible, not enabled, or of the

type
that does not accept focus" and
the SetFocus statement is highlighted!

What did I do wrong !! Here is that section of the sample code:

'................................................. ........
'................................................. ........
' 3rd frame
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then 'check only among the enabled

options
If myOption.Value = True Then myFlag = 3
End If
Next myOption
If myFlag < 3 Then ' a selection is missing in this frame.
' First display a message and then set focus on the 1st enabled option
control on
' this frame
MissingSelection = True
CheckBox = MsgBox("You haven't ... " & Chr(13) & ".. now ?",
vbYesNo, "..")
If CheckBox = vbYes Then 'now SetFocus on the 1st enabled

option
control
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then
myForm.grpInflow.Controls(0).SetFocus
Exit Sub
End If
Next myOption
End If
End If

Regards.



"monir" wrote:

Hi Vasant;

I've implemented your latest suggestion. VBA stll does not like the
SetFocus statemet!

Here is the latest sample code:
------------------------------------------------------------------
' in the user form code's sheet frmOptSelect
Private Sub btnOpen_Click()
' before running the relevant programs, make sure that an option is

selected
in each
' of the ?? frames on the form
'................................................. .............
CheckOptions Me ' notice the Me argument
'................................................. .............
' open files and run my programs
'................................................. .............
Unload Me
End Sub
------------------------------------------------------------------
' in a standard module
Sub CheckOptions(myForm As UserForm)
Dim myOption As Control
Dim myFlag As Integer
Dim CkeckBox
'................................................. .............
myFlag = 0
' 3rd frame
' make sure an option is selected among the enabled options on this

frame
' grpInflow, otherwise display a message and set focus to the 1st

enabled
option on
' this frame
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then
If myOption.Value = True Then myFlag = 3
End If
Next myOption
If myFlag < 3 Then
CheckBox = MsgBox("You haven't selected Inflow Type!!" &

Chr(13) & _
"Select now ?", vbYesNo, "User Form Opt

Prop
Select")
' set focus on the 1st enabled option control button on this frame
If CheckBox = vbYes Then
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then
myForm.grpInflow.Controls(0).SetFocus '

problem
!!!!!!!!!!!!!
Exit Sub
End If
Next myOption
End If
End If
'................................................. .............
' repeat for each frame on the form
'................................................. .............
End Sub
------------------------------------------------------------------

The above changes produced the same error:
.........."Run-time error '2110': Can't move focus to the control

because
it is invisible, not enabled, or of the type that does not accept

focus"
and the SetFocus statement is highlighted!

I apologize for the untidiness of the above sample code, but my

concern
right now is to get the SetFocus method working properly!

Any suggestions ? Thank you.




"Vasant Nanavati" wrote:

Hi Monir:

Of course, if the first option button is disabled, it cannot

accept the
focus. In that case, you have to loop through the option buttons

in the
frame again, find the first one that is not disabled, and set the

focus to
it.

Regards,

Vasant

"monir" wrote in message
...
Vasant;
I replaced the myOption.SetFocus with your statement. The

sample code
layout now looks like this:

' in the user form code's sheet frmOptSelect
Private Sub btnOpen_Click()
' before running the relevant programs, make sure that an option

is
selected
in each
' of the ?? frames on the form
CheckOptions Me ' notice the Me argument


.................................................. ...........................
..
...
' open files and run my programs


.................................................. ...........................
..
...
Unload Me
End Sub

' in a standard module
Sub CheckOptions(myForm As UserForm)
''to check that an option is selected in each of the ?? frames

before
opening and running my relevant prgrams
' check ONLY among the enabled option controls within each frame
Dim myOption As Control
Dim myFlag As Integer
Dim CkeckBox


.................................................. ...........................
..
................
myFlag = 0
' 3rd frame
For Each myOption In myForm.grpInflow.Controls
If myOption.Enabled = True Then
If myOption.Value = True Then myFlag = 3
End If
Next myOption
If myFlag < 3 Then
CheckBox = MsgBox("You haven't selected Inflow Type!!" &

Chr(13) &
"Select now ?", vbYesNo, "User Form Opt Prop Select")
If CheckBox = vbYes Then

myForm.grpInflow.Controls(0).SetFocus
End If


.................................................. ...........................
..
..............
' repeat for each frame on the form


.................................................. ...........................
..
..............
End Sub

The above changes to SetFocus method produced a different error:
.........."Run-time error '2110': Can't move focus to the

control because
it is invisible, not enabled, or of the type that does not

accept focus"

Could the error be associated with the index 0 of Controls ?
Any number of option controls and in any sequence in a

particular frame
under a particular scenario may be disabled.

Thanks again.



"Vasant Nanavati" wrote:

"monir" wrote in message
...



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
ProtectSheet Options are un-checking after macro Roady Excel Discussion (Misc queries) 9 November 16th 11 04:19 PM
SumProduct - checking for multiple options in one column edeaston Excel Discussion (Misc queries) 2 January 30th 09 04:56 PM
Are Error-Checking rules (in Excel Options) workbook-specific? JoeM Excel Discussion (Misc queries) 7 May 4th 08 01:30 AM
Error Checking Options - 2000-2003 brianbishop Excel Discussion (Misc queries) 1 August 11th 06 09:33 PM
spell checking options dvs_47 Excel Worksheet Functions 2 March 6th 06 09:16 PM


All times are GMT +1. The time now is 12:27 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"