By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 2,646 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

Set all form controls to null

Expert 100+
P: 1,892
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
Share this Question
Share on Google+
12 Replies


ADezii
Expert 5K+
P: 8,607
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

Expert 100+
P: 1,892
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
Expert Mod 15k+
P: 31,273
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

Expert 100+
P: 1,892
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
Expert Mod 15k+
P: 31,273
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

Expert 100+
P: 1,892
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
Expert Mod 15k+
P: 31,273
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

Expert 100+
P: 1,892
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
Expert Mod 15k+
P: 31,273
Not a problem Aric.
And congratulations to you for becoming a TSDN Moderator.
Jan 10 '07 #10

Expert 100+
P: 1,892
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
Expert Mod 10K+
P: 14,534
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

P: 1
I had this same problem, thanks to all for your help
Dec 21 '11 #13

Post your reply

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