Clearing Unbound Fields

T

Tatakau

I have a filter form that uses unbound text fields to search for records. A
reset button allows the user to clear all the text fields. Here is the code
associated with it:

Private Sub ClearFields()
Me.leadnum = Null
Me.prefix1 = Null
Me.first1 = Null
Me.middle1 = Null
Me.last1 = Null
Me.suffix1 = Null
Me.prefix2 = Null
Me.first2 = Null
Me.middle2 = Null
Me.last2 = Null
Me.suffix2 = Null
Me.address = Null
Me.city = Null
Me.state = Null
Me.postal = Null
Me.country = Null
Me.phonetype1 = Null
Me.phone1 = Null
Me.phoneext1 = Null
Me.phonetype2 = Null
Me.phone2 = Null
Me.phoneext2 = Null
End Sub

Of course, this sort of code just needs to go. Is there an easy command for
clearing out unbound text fields, perhaps with a loop or with a single
command?

Thanks!

Nick
 
D

Dirk Goldgar

Tatakau said:
I have a filter form that uses unbound text fields to search for
records. A reset button allows the user to clear all the text
fields. Here is the code associated with it:

Private Sub ClearFields()
Me.leadnum = Null
Me.prefix1 = Null
Me.first1 = Null
Me.middle1 = Null
Me.last1 = Null
Me.suffix1 = Null
Me.prefix2 = Null
Me.first2 = Null
Me.middle2 = Null
Me.last2 = Null
Me.suffix2 = Null
Me.address = Null
Me.city = Null
Me.state = Null
Me.postal = Null
Me.country = Null
Me.phonetype1 = Null
Me.phone1 = Null
Me.phoneext1 = Null
Me.phonetype2 = Null
Me.phone2 = Null
Me.phoneext2 = Null
End Sub

Of course, this sort of code just needs to go. Is there an easy
command for clearing out unbound text fields, perhaps with a loop or
with a single command?

Thanks!

Nick

Dim ctl As Access.Control

For Each ctl in Me.Controls
If ctl.Type = acTextBox Then
ctl.Value = Null
End If
Next ctl
 
T

Tatakau

Close. I ran your code but got an error:

Run-time error '438': Object doesn't support this property or method.

Clicking the 'Debug' button highlites the If statement (if ctl.type =
acTextBox then). I don't know VB very well, but I think that since all the
text fields are unbounded that they don't count as controls... the code looks
like it Should work though. :-/

Nick
 
D

Dirk Goldgar

Tatakau said:
Close. I ran your code but got an error:

Run-time error '438': Object doesn't support this property or method.

Clicking the 'Debug' button highlites the If statement (if ctl.type =
acTextBox then). I don't know VB very well, but I think that since
all the text fields are unbounded that they don't count as
controls... the code looks like it Should work though. :-/

Nick

Sorry, that's just a mistake in my "air code". Use this:

If ctl.ControlType = acTextBox Then
 
Top