Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Initializing Form Controls

I have a form that has many checkboxes. I would like to initialize all of
them to false.

What code would cycle thru the controls and determine if it is a checkbox?

For Each chk in Me.Controls
If ????
Me.Controls(chk) = False
End If
Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Initializing Form Controls

Dim ctrl as control
for each ctrl in me.controls
if typeof ctrl is msforms.checkbox then
ctrl.value = false
end if
next ctrl

PosseJohn wrote:

I have a form that has many checkboxes. I would like to initialize all of
them to false.

What code would cycle thru the controls and determine if it is a checkbox?

For Each chk in Me.Controls
If ????
Me.Controls(chk) = False
End If
Next


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Initializing Form Controls

How do I distinguish between a ComboBox, ListBox, TextBox, or CheckBox?

"Dave Peterson" wrote:

Dim ctrl as control
for each ctrl in me.controls
if typeof ctrl is msforms.checkbox then
ctrl.value = false
end if
next ctrl

PosseJohn wrote:

I have a form that has many checkboxes. I would like to initialize all of
them to false.

What code would cycle thru the controls and determine if it is a checkbox?

For Each chk in Me.Controls
If ????
Me.Controls(chk) = False
End If
Next


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Initializing Form Controls

if typeof ctrl is msforms.checkbox then
if typeof ctrl is msforms.listbox then
if typeof ctrl is msforms.textbox then

if typeof ctrl is msforms.combobox then
(but there's only one combobox--the Forms version is called a dropdown.)

Is that what you meant?

PosseJohn wrote:

How do I distinguish between a ComboBox, ListBox, TextBox, or CheckBox?

"Dave Peterson" wrote:

Dim ctrl as control
for each ctrl in me.controls
if typeof ctrl is msforms.checkbox then
ctrl.value = false
end if
next ctrl

PosseJohn wrote:

I have a form that has many checkboxes. I would like to initialize all of
them to false.

What code would cycle thru the controls and determine if it is a checkbox?

For Each chk in Me.Controls
If ????
Me.Controls(chk) = False
End If
Next


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Initializing Form Controls

You would use an If-ElseIf-ElseIf-(etc)-End If block. When you type this...

If TypePf ctrl Is msforms.

or this...

ElseIf TypeOf ctrl Is msforms.

as soon as you type the dot after MsForms, you will be offered a list to
select from.

Rick


"PosseJohn" wrote in message
...
How do I distinguish between a ComboBox, ListBox, TextBox, or CheckBox?

"Dave Peterson" wrote:

Dim ctrl as control
for each ctrl in me.controls
if typeof ctrl is msforms.checkbox then
ctrl.value = false
end if
next ctrl

PosseJohn wrote:

I have a form that has many checkboxes. I would like to initialize all
of
them to false.

What code would cycle thru the controls and determine if it is a
checkbox?

For Each chk in Me.Controls
If ????
Me.Controls(chk) = False
End If
Next


--

Dave Peterson




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Initializing Form Controls

Thank you both, Rick and Dave... I wasn't aware of the TYPEOF syntax.

"Rick Rothstein (MVP - VB)" wrote:

You would use an If-ElseIf-ElseIf-(etc)-End If block. When you type this...

If TypePf ctrl Is msforms.

or this...

ElseIf TypeOf ctrl Is msforms.

as soon as you type the dot after MsForms, you will be offered a list to
select from.

Rick


"PosseJohn" wrote in message
...
How do I distinguish between a ComboBox, ListBox, TextBox, or CheckBox?

"Dave Peterson" wrote:

Dim ctrl as control
for each ctrl in me.controls
if typeof ctrl is msforms.checkbox then
ctrl.value = false
end if
next ctrl

PosseJohn wrote:

I have a form that has many checkboxes. I would like to initialize all
of
them to false.

What code would cycle thru the controls and determine if it is a
checkbox?

For Each chk in Me.Controls
If ????
Me.Controls(chk) = False
End If
Next

--

Dave Peterson



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Initializing Form Controls

When i use your code i get an "invalid use of Me keyword". I don't actually
understand the Me keyword and thus often avoid using it. I have tried alot of
other classes but i can't seem to find the right word to put inplace of 'Me'?

Thank you

"Dave Peterson" wrote:

Dim ctrl as control
for each ctrl in me.controls
if typeof ctrl is msforms.checkbox then
ctrl.value = false
end if
next ctrl

PosseJohn wrote:

I have a form that has many checkboxes. I would like to initialize all of
them to false.

What code would cycle thru the controls and determine if it is a checkbox?

For Each chk in Me.Controls
If ????
Me.Controls(chk) = False
End If
Next


--

Dave Peterson

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Initializing Form Controls

This code assumes that the checkboxes were on a userform and the code was behind
that userform.

If your checkboxes are on a worksheet, then this code won't work.

But if your checkboxes are on a worksheet, what type of checkboxes did you
use--the checkboxes from the Forms toolbar or the checkboxes from the control
toolbox toolbar?

'If they're from the forms toolbar:
ActiveSheet.CheckBoxes.Value = False

'If they're from the control toolbox toolbar:
Dim myCBX As OLEObject
For Each myCBX In ActiveSheet.OLEObjects
If TypeOf myCBX.Object Is MSForms.CheckBox Then
myCBX.Object.Value = False
End If
Next myCBX



Ryan Ragno wrote:

When i use your code i get an "invalid use of Me keyword". I don't actually
understand the Me keyword and thus often avoid using it. I have tried alot of
other classes but i can't seem to find the right word to put inplace of 'Me'?

Thank you

"Dave Peterson" wrote:

Dim ctrl as control
for each ctrl in me.controls
if typeof ctrl is msforms.checkbox then
ctrl.value = false
end if
next ctrl

PosseJohn wrote:

I have a form that has many checkboxes. I would like to initialize all of
them to false.

What code would cycle thru the controls and determine if it is a checkbox?

For Each chk in Me.Controls
If ????
Me.Controls(chk) = False
End If
Next


--

Dave Peterson


--

Dave Peterson
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
Initializing control values of a form TimK Excel Programming 1 September 29th 06 06:34 AM
Initializing UserForm which uses MultiPage controls, part 2 Patrick Simonds Excel Programming 1 August 19th 06 11:06 PM
Initializing UserForm which uses MultiPage controls Patrick Simonds Excel Programming 6 August 15th 06 02:42 AM
ActiveX Controls vs Form Controls Alex Excel Discussion (Misc queries) 1 January 11th 06 08:46 AM
Initializing a Form with multiple forms embedded bforster1 Excel Programming 2 July 14th 04 07:42 PM


All times are GMT +1. The time now is 05:36 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"