473,461 Members | 1,528 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Trying to understand the example code in A97 For Each HELP

MLH
Dim Found, MyObject, MyCollection
Found = False ' Initialize variable.
For Each MyObject In MyCollection ' Iterate through each element.
If MyObject.Text = "Hello" Then ' If Text equals "Hello".
Found = True ' Set Found to True.
Exit For ' Exit loop.
End If
Next

Is it possible for MyCollecion to be the set of records in
tblChkImageFileNames and how would I modify the above code
to do something For Each [CIFNID] field value in MyCollection?

If I'm way off-base here, I'll just use DAO.
Aug 30 '07 #1
8 1359
A set of records (i.e. a recordset) is not the same thing as a collection.
Use a DAO.Recordset.

It sounds like you know how to do that, but here's an example just in case:
http://allenbrowne.com/func-DAO.html...cordsetExample

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"MLH" <CR**@NorthState.netwrote in message
news:je********************************@4ax.com...
Dim Found, MyObject, MyCollection
Found = False ' Initialize variable.
For Each MyObject In MyCollection ' Iterate through each element.
If MyObject.Text = "Hello" Then ' If Text equals "Hello".
Found = True ' Set Found to True.
Exit For ' Exit loop.
End If
Next

Is it possible for MyCollecion to be the set of records in
tblChkImageFileNames and how would I modify the above code
to do something For Each [CIFNID] field value in MyCollection?

If I'm way off-base here, I'll just use DAO.
Aug 30 '07 #2
MLH <CR**@NorthState.netwrote in news:jepdd39jeub25srjq4bm0hnujod7hmodak@
4ax.com:
If I'm way off-base here, I'll just use DAO.
Good idea! That's what most people who are way off-base use.

he! he! he!

--
lyle fairfield

Ceterum censeo Redmond esse delendam
Aug 30 '07 #3
If you would describe what you have and what you are trying to accomplish,
it's more likely that someone could make a useful suggestion. It does not
seem useful to create a Collection to house a Recordset. And, for example,
I think the probability rather high that you don't want to Dim those three
variables all as variants, which is what the first line of your code does.

Larry Linson
Microsoft Access MVP
"MLH" <CR**@NorthState.netwrote in message
news:je********************************@4ax.com...
Dim Found, MyObject, MyCollection
Found = False ' Initialize variable.
For Each MyObject In MyCollection ' Iterate through each element.
If MyObject.Text = "Hello" Then ' If Text equals "Hello".
Found = True ' Set Found to True.
Exit For ' Exit loop.
End If
Next

Is it possible for MyCollecion to be the set of records in
tblChkImageFileNames and how would I modify the above code
to do something For Each [CIFNID] field value in MyCollection?

If I'm way off-base here, I'll just use DAO.

Sep 1 '07 #4
MLH
You're right, Larry. I was just phishing for thoughts. I think Allen's
response the most helpful, indicating that a Collection is not useful
for manipulating or referring to a Recordset. I've never had a use
for Collections and was wondering if anyone used them in that way.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Sat, 01 Sep 2007 06:52:50 GMT, "Larry Linson"
<bo*****@localhost.notwrote:
>If you would describe what you have and what you are trying to accomplish,
it's more likely that someone could make a useful suggestion. It does not
seem useful to create a Collection to house a Recordset. And, for example,
I think the probability rather high that you don't want to Dim those three
variables all as variants, which is what the first line of your code does.

Larry Linson
Microsoft Access MVP
Sep 2 '07 #5

"MLH" <CR**@NorthState.netwrote in message
news:dc********************************@4ax.com...
You're right, Larry. I was just phishing for thoughts. I think Allen's
response the most helpful, indicating that a Collection is not useful
for manipulating or referring to a Recordset. I've never had a use
for Collections and was wondering if anyone used them in that way.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
The only time I created my own collection was when I was exploring the
subject... and, like you, I never quite found a use.

I didn't do comparative timings, but there might be some population where
using a collection and retrieving the members by name, then using some other
property, would be more efficient than arrays, searching and sorting to
retrieve the item, etc.

This approach works, but whether it's "better" or "faster," I couldn't say.
And, the requirement does not arise frequently enough, for me, to warrant
in-depth testing.

Larry
Sep 2 '07 #6
Good to explore.

You probably do use some of the built-in collections, such as Forms (the
collection of open forms.) If you need to open multiple instances of a form,
you might need your own collection to manage them. Demo:
Managing Multiple Instances of a Form
at:
http://allenbrowne.com/ser-35.html

Here's another example where we use collections to manage recursive file
listing (i.e. including subfolders):
List files recursively
at:
http://allenbrowne.com/ser-59.html

Another example of built-in collections: the controls attached to another
control. Most controls have only one control in their collection: the
attached label. For example, if you have a field called Text0, and you want
to change the color of its attached label:
Me.Text0.Controls(0).BackColor = vbRed

An option group can have more than one control in its collection, e.g.:
Function HowManyOptionButtons(grp As OptionGroup) As Integer
Dim ctl As Control
Dim i As Integer
For Each ctl In grp.Controls
If ctl.ControlType = acOptionButton Then
i = i + 1
End If
Next
HowManyOptionButtons = i
End Function

Other common collections include:
- controls on a form/report
- controls in a section of a form/report
- controls on a tab control
- reports

HTH.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"MLH" <CR**@NorthState.netwrote in message
news:dc********************************@4ax.com...
You're right, Larry. I was just phishing for thoughts. I think Allen's
response the most helpful, indicating that a Collection is not useful
for manipulating or referring to a Recordset. I've never had a use
for Collections and was wondering if anyone used them in that way.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Sep 3 '07 #7
On Sep 2, 10:26 pm, "Allen Browne" <AllenBro...@SeeSig.Invalidwrote:
Good to explore.
I used my first collection in 1994, iterating through it. I plan to
report to the group all about its usefulness, just as soon as the
procedure finishes.

Sep 3 '07 #8

"lyle" <ly************@gmail.comwrote in message
news:11**********************@d55g2000hsg.googlegr oups.com...
On Sep 2, 10:26 pm, "Allen Browne" <AllenBro...@SeeSig.Invalidwrote:
>Good to explore.

I used my first collection in 1994, iterating through it. I plan to
report to the group all about its usefulness, just as soon as the
procedure finishes.
I think Lyle is doing my performance testing for me, and I very much look
forward to the result, should the test finish before the computer burns out.

:-)

Larry
Sep 4 '07 #9

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

Similar topics

3
by: mmccaws | last post by:
Thanks ahead for your help I'm trying to learn what I can do with echo and print statements. I figured out the echo statement and below is the simple version using print. I've tried two dozen...
8
by: Rich Grise | last post by:
I think I've finally found a tutorial that can get me started: http://www.zib.de/Visual/people/mueller/Course/Tutorial/tutorial.html and I've been lurking for awhile as well. What happened is,...
4
by: Alex | last post by:
I have searched the boards but I have not found what I am looking for yet. I have a form with two combo boxes. When the user makes a selection in both of the combo boxes the information will...
2
by: DC | last post by:
Hi, I need to asynchronously read from a network (TCP) stream, and I am having trouble with retrieving whole blocks; I get a break in the data block every 1460 bytes which relates to network...
4
by: Dave | last post by:
I used the following class and .aspx code below to understand how static works on variables and methods taken from...
1
by: Henry | last post by:
Hi. I've been trying to modify my dataset and have been unsucessful. Any help would be great. What I have is a dataset in a session variable. Here is what I have done to stored into the dataset...
22
by: RSH | last post by:
Hi, I have been reading on interfaces working on samples I've run across on the web. For the life of me I cannot seem to grasp them. It appears to me that interfaces are simply blueprints to...
27
by: jm | last post by:
I am having trouble understanding the purposes of an interface, even though the concept of interfaces is around me all the time (user interface, for example). I'm just not understanding software...
1
by: hmbscully | last post by:
I am trying to send a complex mutli-part email with inline attachments between html pieces. I originally wrote the code in Perl with the MIME::Lite module, which worked fine. My attempts to...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
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.