473,809 Members | 2,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Set all form controls to null

1,892 Recognized Expert Top Contributor
Currently I am manually setting each control on my form to null to reset. Does anyone know how to do this with a loop or a more simple command? I've seen some make shift control arrays but none that would work for me.

Thanks,
Aric
Jan 9 '07 #1
12 16032
ADezii
8,834 Recognized Expert Expert
Currently I am manually setting each control on my form to null to reset. Does anyone know how to do this with a loop or a more simple command? I've seen some make shift control arrays but none that would work for me.

Thanks,
Aric
Try
Expand|Select|Wrap|Line Numbers
  1. On Error Resume Next
  2.  
  3. Dim ctl As Control
  4. For Each ctl In Me.Controls
  5.   ctl.Value = Null
  6. Next
Jan 9 '07 #2
AricC
1,892 Recognized Expert Top Contributor
I've tried something like that but I get the error that the object doesn't support that property/method.
Jan 9 '07 #3
NeoPa
32,579 Recognized Expert Moderator MVP
If you look carefully you'll see that there is code included to avoid that situation arising (On Error Resume Next).
Try this code out as exactly as possible and let us know how you get on.
At worst you'll waste five minutes.
If it doesn't work properly for you then come back and let us know what went wrong and we'll see if we can't find another solution for you.
Jan 9 '07 #4
AricC
1,892 Recognized Expert Top Contributor
I think I got it fixed, here is the code I used, (an interesting work around):
Expand|Select|Wrap|Line Numbers
  1. Private Sub ResetFields()
  2. Dim ctlTextBox As Control
  3.  
  4.     For Each ctlTextBox In Me.Controls
  5.         If TypeName(ctlTextBox) = "TextBox" Then
  6.             ctlTextBox.Value = Null
  7.         End If
  8.      Next ctlTextBox
  9.  
  10.  
  11. End Sub
  12.  
And I'm using this for combo boxes:
Expand|Select|Wrap|Line Numbers
  1.     For Each ctlComboBox In Me.Controls
  2.         If TypeName(ctlComboBox) = "ComboBox" Then
  3.             ctlComboBox.Value = Null
  4.         End If
  5.      Next ctlComboBox
  6.  
Jan 9 '07 #5
NeoPa
32,579 Recognized Expert Moderator MVP
Maybe this could work better for you (similar results of course - just tidier code).
Expand|Select|Wrap|Line Numbers
  1. Private Sub ResetFields()
  2. Dim ctlTextBox As Control
  3.  
  4.     For Each ctlTextBox In Me.Controls
  5.         If TypeName(ctlTextBox) = "TextBox" _
  6.         Or TypeName(ctlTextBox) = "ComboBox" Then _
  7.             ctlTextBox.Value = Null
  8.      Next ctlTextBox
  9. End Sub
PS. It would be interesting, for me as well as any future readers of the thread, if you could post what happened when you tried ADezii's code.
Jan 9 '07 #6
AricC
1,892 Recognized Expert Top Contributor
It would be interesting, for me as well as any future readers of the thread, if you could post what happened when you tried ADezii's code.
If you use this code:
Expand|Select|Wrap|Line Numbers
  1. Dim ctl As Control
  2. For Each ctl In Me.Controls
  3.   ctl.Value = Null
  4. Next
You will get the following Error Number: 438 Error Description: Object doesn't support this method or property.
Jan 9 '07 #7
NeoPa
32,579 Recognized Expert Moderator MVP
I understand that Aric, but that wasn't the code posted.
You left out a very important line :
Expand|Select|Wrap|Line Numbers
  1. On Error Resume Next
which should ensure that the error is never triggered but that all controls (Text- & Combo-Boxes) that can be set to Null are (See Post #4).
Jan 9 '07 #8
AricC
1,892 Recognized Expert Top Contributor
I understand that Aric, but that wasn't the code posted.
You left out a very important line :
Expand|Select|Wrap|Line Numbers
  1. On Error Resume Next
which should ensure that the error is never triggered but that all controls (Text- & Combo-Boxes) that can be set to Null are (See Post #4).
I didn't use that line in my testing, only the for loop. I log my errors with error handling. Sorry for the confusion.
Jan 10 '07 #9
NeoPa
32,579 Recognized Expert Moderator MVP
Not a problem Aric.
And congratulations to you for becoming a TSDN Moderator.
Jan 10 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1815
by: Yasutaka Ito | last post by:
Hi, As you know, all the non-ui components (like Timer control, etc.) that sit on the form are contained in its private variable 'components'. How can I enumerate such components from any form instance given to me? I have no access to the source of the given form instance, but I can impose that the form be inherited from certain base class I provide. Would appreciate any inputs. If there is other way to access the non-ui
11
18844
by: Jozef | last post by:
I have some old code that I use from the Access 95 Developers handbook. The code works very well, with the exception that it doesn't seem to recognize wide screens, and sizes tab controls so that they are too big and wind up covering up some of the fields on the main form. Is there any good code out there that works in a similar fashion that will also either a) stretch the form width wise on widescreens or b), rely on height rather than...
3
14168
by: Chris | last post by:
Hi, I'm trying to append text from another class to a generic richTextBox that I've added to a Windows form. I can't seem to figure out how to expose the richTextBox to append text to it. Thanks in advance, Chris
2
8317
by: Jaikumar | last post by:
Hi, 1) I have created one windows application, In the main form ( form1) i have added one usercontrol (usercontrol1), In that user control i am drawing one image. 2) In the UserControl1 i am showing one transparent form (form3) when ever user preseed left mouse button. 3) The form3 has one transparent user control (usercontrol2) that paints circles. That measn the circles will show on top the usercontrol1 image. 4) The form3 border style...
6
6229
by: Claus Holm | last post by:
I'm trying to enable a menuitem in the parent form from a mdichild. Rather than making the menuitems public, I'd go for a public method in the parent form to do the change, but when I call the method from the mdichild, I get this error: C:\MyProjects\Visual Studio Projects\Tournament\Forms\frmLogin.cs(69): The name 'test' does not exist in the class or namespace 'Tournament.frmLogin' frmLogin is the mdichild.
11
3488
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and click a button to determine whether the zip code is unique. If the zip code is not unique, another form/dialog is displayed (fclsLookup) - lookup form/dialog. The zip code and zipid are both passed to the lookup form/dialog by reference. I...
8
4417
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and click a button to determine whether the zip code is unique. If the zip code is not unique, another form/dialog is displayed (fclsLookup) - lookup form/dialog. The zip code is passed to the lookup form/dialog by reference. I then load a...
4
3524
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I click a button on a pop-up window the javascript for that button click does a 'button.form.submit'. On the Server side there is a Button click event for this button, but for some reason it no longer fires. It worked fine before and everything...
6
2435
by: ahmad.humyn | last post by:
I want to call a hidden form. My code goes something like in which the main calls form1. form1 has a button which creates & calls form2 and hides itself. Now I have a button in form2 which if pressed should dispose form2 and then unhide and focus form1. -------------------------------------------------- static void Main() { ..... Application.Run(new Form1());
4
13362
by: Toze | last post by:
I'm using a assembly to load my apllication (ex: Mobi.exe), and now I need to list all forms in my apllication and list all controls (ex: txtname;btnname) inside of each form.
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10387
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10120
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5689
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.