473,324 Members | 2,313 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Disable all text boxes on form at once

how would you disable all text boxes on a form at once/

I thought

dim tx as textbox
for each tx in me.controls
tx.enabled = false
next

but that crashes, what do you guys suggest? thanks
Nov 20 '05 #1
8 15395
* "Brian Henry" <br**********@newsgroups.nospam> scripsit:
how would you disable all text boxes on a form at once/

I thought

dim tx as textbox
for each tx in me.controls
tx.enabled = false
next

but that crashes, what do you guys suggest?


<URL:http://dotnet.mvps.org/dotnet/samples/controls/downloads/EnumerateControls.zip>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:ed**************@tk2msftngp13.phx.gbl...
how would you disable all text boxes on a form at once/

I thought

dim tx as textbox
for each tx in me.controls
tx.enabled = false
next

but that crashes, what do you guys suggest? thanks


Dim c As Control
For Each c In Me.Controls
If TypeOf c Is TextBox Then
c.Enabled = False
End If
Next

--
Sven Groot

Nov 20 '05 #3
"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:ed**************@tk2msftngp13.phx.gbl...
how would you disable all text boxes on a form at once/

dim tx as textbox
for each tx in me.controls


This will /only/ work if /every/ control on the form is a TextBox.
Otherwise, it will get upset trying to cast, say, a Label into your
TextBox variable.

Try this (I'm using VB'2003 here)

For Each ctl as Control in Me.Controls
If ctl Is TextBox Then
ctl.Enabled = False
End If
Next

HTH,
Phill W.
Nov 20 '05 #4
Hi Brian,

The one I like, I typed it in here so watch typos

I hope this helps

Cor

\\\\
Private sub Set
doset(Me)
end sub
Private Sub doSet(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
if typeof ctr is textbox then
ctr.enabled = false
end if
doSet(ctr)
Next
End Sub
////
Nov 20 '05 #5
"Brian Henry" <br**********@newsgroups.nospam> schrieb
how would you disable all text boxes on a form at once/

I thought

dim tx as textbox
for each tx in me.controls
tx.enabled = false
next

but that crashes, what do you guys suggest? thanks


Not all controls on the Form are textboxes, so whenever, within the loop, a
control is assigned to 'tx' that is not a textbox, an InvalidCastException
occurs. Instead:

dim o as object
for each o in me.controls
if typeof o is textbox then
directcast(o, textbox).enabled = false
end if
next

Note that this only processes the Textboxes directly placed on the Form, not
those eg placed on a groupbox on the Form.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #6
Hi Armin,
Note that this only processes the Textboxes directly placed on the Form, not those eg placed on a groupbox on the Form.


Have a look at that nice routine I made for it.
(It is one of them of course, however this one I like specially in this
situation, it is very good when you have to set one handler for all
controls)

Cor
Nov 20 '05 #7
oh yes, the is.. dumb me forgetting about types
"Sven Groot" <sv*******@gmx.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:ed**************@tk2msftngp13.phx.gbl...
how would you disable all text boxes on a form at once/

I thought

dim tx as textbox
for each tx in me.controls
tx.enabled = false
next

but that crashes, what do you guys suggest? thanks


Dim c As Control
For Each c In Me.Controls
If TypeOf c Is TextBox Then
c.Enabled = False
End If
Next

--
Sven Groot

Nov 20 '05 #8
"Armin Zingler" <az*******@freenet.de> schrieb
[bla]

sorry for sounding like an echo... ;)
--
Armin
Nov 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: rked | last post by:
I have an order form with about a hundred textboxes saying 0. People change the zero to something else to tell quantity of field. I am submitting page via asp and cdo. Is there a function that...
6
by: Lloyd | last post by:
How do you make a textbox enabled or disabled ??? i have tried Textbox.disable or enable but the controls apparently dont have this property programmically ???
9
by: Bill (Unique as my name) | last post by:
Please suggest some links or sources which show how to set up form text boxes in VBA. Thank you so much.
5
by: ZaphodBBB | last post by:
I have a form that is used just to review previously saved records.(1 record at a time). It also allows just a couple of fields to be updatable (in a given record)and resaved. I load all the...
1
by: Nagel Oxles | last post by:
My form has has seven Text Boxes to receive user input. Users fall into either of two categories, Current and New. 'Command_Button_New' changes the visible property of four text Boxes and their...
11
by: jwessner | last post by:
I have a form (Form1) which contains basic Project data and a subform listing the personnel assigned to the Project as a continuous form. Selecting a person on that project and clicking on a command...
1
by: stewdizzle | last post by:
I have a from with three radio buttons (same group) and three text boxes. The radio buttons give the user a choice of uploading one, two, or three images. Currently, I have the text boxes load as...
4
by: ingaivey | last post by:
I have 81 text boxes on a form and would like to create a text array in code that will equate to these boxes on the form. Once I've assigned each text box from the form to the array entry, I'd just...
4
by: Eric` | last post by:
I am trying to create a database that will track personal information on clients I am trying to create a checkbox for marital status specifically single that will disable the other text boxes such as...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.