473,472 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Enumerating Textboxes

I want to do a quick check of a group of textboxes only to see if they
contain anything.

I tried this code but it appears to go from box to box based on the
boxes time of creation.

Is it possible to reset creation time so the loop checks from top to
bottom without skipping around.

Private Sub Command49_Click()
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
If ctl.Tag = "Verify Data" Then
If ctl.Value > "" Then
ctl.Value = ctl.Value
Else
MsgBox "Missing Data"
ctl.SetFocus
Exit For
End If
End If
End If
Next
End Sub

Thanks, Rick

Nov 18 '05 #1
11 1686
Hi Rick,

Suggest doing a Cut and then Paste of the textboxes in your form. Perhaps
that will reset the
creation time of the textboxes in top to bottom order.

HTH. Linda

"2D Rick" <rb*******@compuserve.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I want to do a quick check of a group of textboxes only to see if they
contain anything.

I tried this code but it appears to go from box to box based on the
boxes time of creation.

Is it possible to reset creation time so the loop checks from top to
bottom without skipping around.

Private Sub Command49_Click()
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
If ctl.Tag = "Verify Data" Then
If ctl.Value > "" Then
ctl.Value = ctl.Value
Else
MsgBox "Missing Data"
ctl.SetFocus
Exit For
End If
End If
End If
Next
End Sub

Thanks, Rick

Nov 18 '05 #2
Order stayed the same if I Cut and Pasted within same form and pasting
into new form.

Thanks for the reply
RICK

Nov 18 '05 #3
2D Rick wrote in message
<11**********************@g43g2000cwa.googlegroups .com> :
I want to do a quick check of a group of textboxes only to see if they
contain anything.

I tried this code but it appears to go from box to box based on the
boxes time of creation.

Is it possible to reset creation time so the loop checks from top to
bottom without skipping around.

Private Sub Command49_Click()
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
If ctl.Tag = "Verify Data" Then
If ctl.Value > "" Then
ctl.Value = ctl.Value
Else
MsgBox "Missing Data"
ctl.SetFocus
Exit For
End If
End If
End If
Next
End Sub

Thanks, Rick


I think there was a thread in this NG not long ago discussing
this. If I'm not mistaken, I think the answer was no (at least
for practical purposes), think of collections as unordered.

Here's one suggestion
- use a naming convention on the boxes that makes it
possible to loop them as "control array", i e

txt1, txt2, txt3..

for lngcounter = 1 to N
msgbox me.controls("txt" & cstr(lngcounter)).value
next lngcounter

--
Roy-Vidar

Nov 18 '05 #4
How do you know that the code is looping through the textboxes based on
creation time? I'm not challenging you, just curious as to how that
works. You may wish to change the tab order of your textboxes so it's
sequential from top to bottom of the form to see if this will solve the
issue.

The code I usually use to loop through textboxes is thus:
Dim ctl As Control
For Each ctl In frmFormName.Controls
If ctl.ControlType = acTextBox Then
If ctl.Text="" Then
MsgBox "Textless"
End If
End If
Next ctl

Nov 18 '05 #5
Thanks Roy And Steve

The tab order is set from top to bottom and works as planned.
The textboxes were created from top to bottom on day one.
Since then I have shuffled the placement of the text boxes to help in
input flow of data.
They must have some hidden reference in controls collection????????

Rick

Nov 18 '05 #6
I have just looked at the Object Browser and note that a Textbox has a
property TabIndex. You could use this to sort the Controls collection.

Give it try

Nov 18 '05 #7
Jim's got a point. You could loop through all available textboxes and
store their names in an array along with their TabIndex, then sort the
array by TabIndex, and loop through the array checking the Text
property of each textbox.

Nov 18 '05 #8
"Squirrel" <wi*****@covad.net> wrote in
news:67***************************@msgid.meganewss ervers.com:
Suggest doing a Cut and then Paste of the textboxes in your form.
Perhaps that will reset the
creation time of the textboxes in top to bottom order.


The z order is set by when you put the control on the form, so if
you bring the control to front (or sent id to back) you are moving
it in the z order.

I also think the basic task being performed is *wrong* in the first
place. If the value is required, then don't allow the record to be
saved until all fields are filed out. That can be done by having the
AfterUpdate event of each of the required controls check all the
required fields and enable the SAVE button when everything is filled
out. This would include informing a user that a required field can't
be Null if they delete the value in a required field.

I just think it's user-hostile to present multiple validation
messages like this, one field after the other. Instead, it's better,
seems to me, to tell the user that all required fields have not been
filed out, tell them which ones are missing, and then dump them back
to the form, rather than hitting them with message box after message
box.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 18 '05 #9
I always find your advice useful or though provoking, so I'll consider
what you've written.
Thanks for the reply
Rick

ps. your colorful skirmishes with the prickly bunch lighten my day.

Nov 18 '05 #10
Thanks Jim and Steve,
Storing and sorting an array are new to me but not "out of range" of my
knowledge base.
Rick

Nov 18 '05 #11
David is right about the underlying theory. Another way to make this
procedure more user-friendly would be to simply check all the text
fields when the user clicks the Save button. One thing I usually do is
create a string and then use IF statements to add items to the string.
Example:
If txtBox1="" Or IsNull(txtBox1) Then
str=str+"Please enter a value for txtBox1." + vbCrLf
ElseIf txtBox2="" Or IsNull(txtBox2) Then
str=str+"Please enter a value for txtBox2." + vbCrLf
End If

lblErrorMessage=str

This way, if the user leaves both boxes empty, they are presented with
the following message:
Please enter a value for txtBox1.
Please enter a value for txtBox2.

At the same time, and without extra code, if the user leaves only one
box blank, he will still get the appropriate message.

Nov 21 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Brett Mostert | last post by:
Hi, I need to be able to Enumerate through Printer Drivers, ports, printers and so fourth. And even add printers, ports, and drivers and setup printers. Sofar i can do all of the following...
2
by: Bishman | last post by:
Can anyone suggest a method of enumerating instances of MSDE 2000 without using DMO ? Using C++, MFC, and ADO. Thanks
4
by: Lyn | last post by:
Hi, This question may seem a bit academic... To learn more about Access VBA, I have been enumerating the properties of various form controls. This was mostly successful and I have learned a lot...
1
by: Kevin | last post by:
Hi, How can I enumerate a linked list while being hable to delete any number of elements while enumerating ? I was using: struct st { ... struct st *prev;
0
by: Michael C | last post by:
Hi all, After a lot of research, I've come to some realizations about enumerating Named Instances of MSDE. NetServerEnum() Win32 API function doesn't work, SQL-DMO doesn't work, no standard...
4
by: Brett Mostert | last post by:
Hi, I need to be able to Enumerate through Printer Drivers, ports, printers and so fourth. And even add printers, ports, and drivers and setup printers. Sofar i can do all of the following...
2
by: Tony | last post by:
I have this problem - I have a hashtable, containing a list of filenames. Every 60 seconds, I have a thread that enumerates thru this hashtable, and based on some simple logic, some of the items...
1
by: Glenn Leifheit | last post by:
Does anyone have any sample code on enumerating network shares with vb.net. I here you need to use wither an API or WMI, or are there other recomendations. Thanks Glenn
1
by: Shelby | last post by:
Hi, I would like to modify the object's value while enumerating but I get this error Additional information: Collection was modified; enumeration operation may not execute. This is my code: ...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.