Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Editing controls on a userform en masse

I have a userform that has multiple pages, each page has various controls
(TextBox, ComboBox, CheckBox). Is there code that I can use to clear all of
the values in the userform?

I was thinking "For Each", but I am new to code and keep getting lost...

Any help is appreciated!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default Editing controls on a userform en masse

Shane,

The code below is untested and will need to be altered for your specific
case, but it should work. The code assumes that the MultiPage control on the
form is named "frmPgs".

Best,

Matthew Herbert

Dim Pg As Page
Dim Ctrl As MSForms.Control
'check "Tools | Reference | Microsoft Forms 2.0 Object Library" to
' use MSForms; otherwise, simply use Dim Ctrl As Control

'loop through each page in the Pages collection of the form
For Each Pg In frmPgs.Pages

'loop through each control on the page
For Each Ctrl In Pg.Controls

'get the desired control type
If TypeOf Ctrl Is MSForms.TextBox Then

'set the control value
Ctrl.Value = ""
End If
Next Ctrl
Next Pg

"Shane" wrote:

I have a userform that has multiple pages, each page has various controls
(TextBox, ComboBox, CheckBox). Is there code that I can use to clear all of
the values in the userform?

I was thinking "For Each", but I am new to code and keep getting lost...

Any help is appreciated!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Editing controls on a userform en masse

Using code like this, I get a type mismatch error... here is the code I am
using. It runs on clicking a commandbutton on the userform, but outside of
the multipage control. I want it to reset EVERY control in the userform.

Dim Ctrl As MSForms.Control
Dim Pg As Page
For Each Pg In UserForm1.MultiPage1.Pages
For Each Ctrl In Pg.Controls
If TypeOf Ctrl Is MSForms.TextBox Then
Ctrl.Value = ""
Else
If TypeOf Ctrl Is MSForms.ComboBox Then
Ctrl.Value = ""
Else
If TypeOf Ctrl Is MSForms.CheckBox Then
Ctrl.Value = False
Else
If TypeOf Ctrl Is MSForms.OptionButton Then
Ctrl.Value = False
End If
End If
End If
End If
Next Ctrl
Next Pg

"Matthew Herbert" wrote:

Shane,

The code below is untested and will need to be altered for your specific
case, but it should work. The code assumes that the MultiPage control on the
form is named "frmPgs".

Best,

Matthew Herbert

Dim Pg As Page
Dim Ctrl As MSForms.Control
'check "Tools | Reference | Microsoft Forms 2.0 Object Library" to
' use MSForms; otherwise, simply use Dim Ctrl As Control

'loop through each page in the Pages collection of the form
For Each Pg In frmPgs.Pages

'loop through each control on the page
For Each Ctrl In Pg.Controls

'get the desired control type
If TypeOf Ctrl Is MSForms.TextBox Then

'set the control value
Ctrl.Value = ""
End If
Next Ctrl
Next Pg

"Shane" wrote:

I have a userform that has multiple pages, each page has various controls
(TextBox, ComboBox, CheckBox). Is there code that I can use to clear all of
the values in the userform?

I was thinking "For Each", but I am new to code and keep getting lost...

Any help is appreciated!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default Editing controls on a userform en masse

Shane,

I threw together some quick code and got the same error. It's odd to me
that VBA isn't assign a single Page from the MultiPage to the Pg variable
(which is dimensioned as a Page). Anyhow, change the Pg data type from Page
to Object. Also, you can narrow up your nested If Statements with some
ElseIf statements (see below).

Best,

Matt

Dim objPg As Object
Dim Ctrl As MSForms.Control

For Each objPg In UserForm1.MultiPage1.Pages

For Each Ctrl In objPg.Controls

If TypeOf Ctrl Is MSForms.TextBox Then
Ctrl.Value = ""
ElseIf TypeOf Ctrl Is MSForms.ComboBox Then
Ctrl.Value = ""
ElseIf TypeOf Ctrl Is MSForms.CheckBox Then
Ctrl.Value = False
ElseIf TypeOf Ctrl Is MSForms.OptionButton Then
Ctrl.Value = False
End If

Next Ctrl
Next objPg


"Shane" wrote:

Using code like this, I get a type mismatch error... here is the code I am
using. It runs on clicking a commandbutton on the userform, but outside of
the multipage control. I want it to reset EVERY control in the userform.

Dim Ctrl As MSForms.Control
Dim Pg As Page
For Each Pg In UserForm1.MultiPage1.Pages
For Each Ctrl In Pg.Controls
If TypeOf Ctrl Is MSForms.TextBox Then
Ctrl.Value = ""
Else
If TypeOf Ctrl Is MSForms.ComboBox Then
Ctrl.Value = ""
Else
If TypeOf Ctrl Is MSForms.CheckBox Then
Ctrl.Value = False
Else
If TypeOf Ctrl Is MSForms.OptionButton Then
Ctrl.Value = False
End If
End If
End If
End If
Next Ctrl
Next Pg

"Matthew Herbert" wrote:

Shane,

The code below is untested and will need to be altered for your specific
case, but it should work. The code assumes that the MultiPage control on the
form is named "frmPgs".

Best,

Matthew Herbert

Dim Pg As Page
Dim Ctrl As MSForms.Control
'check "Tools | Reference | Microsoft Forms 2.0 Object Library" to
' use MSForms; otherwise, simply use Dim Ctrl As Control

'loop through each page in the Pages collection of the form
For Each Pg In frmPgs.Pages

'loop through each control on the page
For Each Ctrl In Pg.Controls

'get the desired control type
If TypeOf Ctrl Is MSForms.TextBox Then

'set the control value
Ctrl.Value = ""
End If
Next Ctrl
Next Pg

"Shane" wrote:

I have a userform that has multiple pages, each page has various controls
(TextBox, ComboBox, CheckBox). Is there code that I can use to clear all of
the values in the userform?

I was thinking "For Each", but I am new to code and keep getting lost...

Any help is appreciated!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Editing controls on a userform en masse

Works fantastic! Thank you so much!

"Matthew Herbert" wrote:

Shane,

I threw together some quick code and got the same error. It's odd to me
that VBA isn't assign a single Page from the MultiPage to the Pg variable
(which is dimensioned as a Page). Anyhow, change the Pg data type from Page
to Object. Also, you can narrow up your nested If Statements with some
ElseIf statements (see below).

Best,

Matt

Dim objPg As Object
Dim Ctrl As MSForms.Control

For Each objPg In UserForm1.MultiPage1.Pages

For Each Ctrl In objPg.Controls

If TypeOf Ctrl Is MSForms.TextBox Then
Ctrl.Value = ""
ElseIf TypeOf Ctrl Is MSForms.ComboBox Then
Ctrl.Value = ""
ElseIf TypeOf Ctrl Is MSForms.CheckBox Then
Ctrl.Value = False
ElseIf TypeOf Ctrl Is MSForms.OptionButton Then
Ctrl.Value = False
End If

Next Ctrl
Next objPg


"Shane" wrote:

Using code like this, I get a type mismatch error... here is the code I am
using. It runs on clicking a commandbutton on the userform, but outside of
the multipage control. I want it to reset EVERY control in the userform.

Dim Ctrl As MSForms.Control
Dim Pg As Page
For Each Pg In UserForm1.MultiPage1.Pages
For Each Ctrl In Pg.Controls
If TypeOf Ctrl Is MSForms.TextBox Then
Ctrl.Value = ""
Else
If TypeOf Ctrl Is MSForms.ComboBox Then
Ctrl.Value = ""
Else
If TypeOf Ctrl Is MSForms.CheckBox Then
Ctrl.Value = False
Else
If TypeOf Ctrl Is MSForms.OptionButton Then
Ctrl.Value = False
End If
End If
End If
End If
Next Ctrl
Next Pg

"Matthew Herbert" wrote:

Shane,

The code below is untested and will need to be altered for your specific
case, but it should work. The code assumes that the MultiPage control on the
form is named "frmPgs".

Best,

Matthew Herbert

Dim Pg As Page
Dim Ctrl As MSForms.Control
'check "Tools | Reference | Microsoft Forms 2.0 Object Library" to
' use MSForms; otherwise, simply use Dim Ctrl As Control

'loop through each page in the Pages collection of the form
For Each Pg In frmPgs.Pages

'loop through each control on the page
For Each Ctrl In Pg.Controls

'get the desired control type
If TypeOf Ctrl Is MSForms.TextBox Then

'set the control value
Ctrl.Value = ""
End If
Next Ctrl
Next Pg

"Shane" wrote:

I have a userform that has multiple pages, each page has various controls
(TextBox, ComboBox, CheckBox). Is there code that I can use to clear all of
the values in the userform?

I was thinking "For Each", but I am new to code and keep getting lost...

Any help is appreciated!



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
VBA Userform - Editing Controls (Similar to Dataform) (Excel 97) Phendrena Excel Programming 2 November 19th 08 11:59 AM
userform controls natanz[_2_] Excel Programming 3 November 2nd 05 02:38 PM
Editing controls after testing twintrbl Excel Programming 3 June 7th 05 07:27 PM
Help please with UserForm controls sa3214 Excel Programming 4 July 2nd 04 03:00 AM
Add controls to UserForm Vyyk Drago Excel Programming 3 August 26th 03 01:22 PM


All times are GMT +1. The time now is 10:35 PM.

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

About Us

"It's about Microsoft Excel"