Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Could I loop this? What's the syntax? 3

Status
Not open for further replies.

jasonmac

Programmer
Nov 14, 2002
175
US
Hi everyone. I when a specific event occurs I want all of the text boxes on my form to be cleared. Here is an example of how it is done now

Forms!frmReportCriteria!txtStartDate.Value = ""
Forms!frmReportCriteria!txtEndDate.Value = ""
Forms!frmReportCriteria!txtPress1.Value = ""
Forms!frmReportCriteria!txtPress2.Value = ""
Forms!frmReportCriteria!txtPress3.Value = ""
Forms!frmReportCriteria!txtPress4.Value = ""
Forms!frmReportCriteria!txtPress5.Value = ""
Forms!frmReportCriteria!txtCode1.Value = ""
Forms!frmReportCriteria!txtCode2.Value = ""
Forms!frmReportCriteria!txtCode3.Value = ""
Forms!frmReportCriteria!txtCode4.Value = ""
Forms!frmReportCriteria!txtCode5.Value = ""

Is there a way to make this into a loop, I'm not sure of the syntax. Can anyone help?
 
The following:

[tt]
Forms!frmReportCriteria!txtStartDate.Value = ""
Forms!frmReportCriteria!txtEndDate.Value = ""
For i = 1 To 5
Forms("frmReportCriteria")("txtPress" & Cstr(i)).Value = ""
Forms("frmReportCriteria")("txtCode" & CStr(i)).Value = ""
[/tt]

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
Jason,

I am not sure you really wish to do this. A form is showing the data in one record of a recordset. To clear those bound textfields means to blank out the fields in the underlying record. Is that what you wish to do?

rollie@bwsys.net

P.S. Sure you can loop it.
 
oops...for the

Next i

as the last line

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
There are a bunch of ways to do this. One that I use from time to time is to make the tag of each of the controls you want to act on the same for all of these control. You can highlight them all and put "ClearMe" in the tag property.

Then write code that looks something like this (untested aircode):

dim ctl as control

for each ctl in me.controls
if ctl.tag = "ClearMe" then
ctl = ""
end if
next ctl

Try that and see if it works for you.

Jeremy

==
Jeremy Wallace
AlphaBet City Dataworks
Access Databases for Non-Profit Organizations

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 

That seems to be exactly what I'm looking for, Jeremy. Thanks to everyone who answered. In case anyone is concerned all of the text boxes are unbound.
Thanks again!

Jason
 
Nice usage of the .tag Jeremy....hadn't thought of that.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
Could anyone tell me why the following code does not work?

Dim intCounter As Integer
Dim ctl As Control

intCounter = 0

For Each ctl In Me.Controls
If ctl <> &quot;&quot; Then
intCounter = intCounter + 1
End If
Next I

I get an error that says:

object does not support this property of method.

When I debug the If line is highlighted.
Am i doing something wrong?
 
Because you are looping thru all controls, and not all controls might be evaluated against &quot;&quot; (labels for instance).

Try limiting your loop to only the types of control you want to perform something on:

[tt]For Each ctl In Me.Controls
Select Case ctl.ControlType
Case acTextBox, acCombobox
If ctl.Value <> &quot;&quot; Then
intCounter = intCounter + 1
End If
End Select
Next I[/tt]

- AND checking for &quot;&quot; might not be sufficient, Len(ctl.Value & vbNullString)>0, Isnull(ctl.Value)... might also be worth considering.

Roy-Vidar
 
Are you trying to count up any control that is empty???

If ctl.Value <> &quot;&quot; Then

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
Worked Like a charm Roy! I see now why I had to limit the controls it was looking at. A star to you my friend!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top