472,804 Members | 945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Set all form controls to null

1,892 Expert 1GB
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 15771
ADezii
8,834 Expert 8TB
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 Expert 1GB
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,534 Expert Mod 16PB
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 Expert 1GB
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,534 Expert Mod 16PB
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 Expert 1GB
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,534 Expert Mod 16PB
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 Expert 1GB
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,534 Expert Mod 16PB
Not a problem Aric.
And congratulations to you for becoming a TSDN Moderator.
Jan 10 '07 #10
AricC
1,892 Expert 1GB
Not a problem Aric.
And congratulations to you for becoming a TSDN Moderator.
Thanks Adrian, glad to help out! I appreciate all the help I get in the Access forum.
Jan 10 '07 #11
MMcCarthy
14,534 Expert Mod 8TB
Thanks Adrian, glad to help out! I appreciate all the help I get in the Access forum.
Aric

If your form is unbound would Me.Refresh not work.

Mary
Jan 12 '07 #12
I had this same problem, thanks to all for your help
Dec 21 '11 #13

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

Similar topics

4
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...
11
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...
3
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. ...
2
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...
6
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...
11
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...
8
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...
4
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...
6
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...
4
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.
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.