473,409 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

For Loop error

I'm trying to create an "For Each...Next" setup where I can go through every row on a table. I need to check a specific column, and depending on that value I have a count running. It seems to work but it keeps raising a "Error 424: Object required" box.

Any Ideas? Btw this code is being executed on a form that displays statistics.

Expand|Select|Wrap|Line Numbers
  1. For Each dr In Tables.FCG10.rows
  2.     Select Case dr.[field]
  3.         Case "person1"
  4.             longGuinta = longGuinta + 1
  5.         Case Is = Null
  6.             longUncontacted = longUncontacted + 1
  7.     End Select
  8. Next dr
  9.  
May 8 '10 #1

✓ answered by Jim Doherty

Hello Anduril12 :)

I am not sure I quite understand the actual specifics intentions of your code post. My assumption (and I may well be wrong in my interpretation) is that you want to examine a column named 'person1' in a table called FCG10 and then loop down that column to apply some logic as posted to increment your variables+1

I see you framing of your code is inclined towards looping for each field but what is the point if you know the name of the column? Why not just call that individual column as a 'single column' dataset ie not drag up the entire table.

The following is my interpretation of what I 'think' you are trying to do

Expand|Select|Wrap|Line Numbers
  1.  Dim dbs As DAO.Database
  2.   Dim rst As DAO.Recordset
  3.   Dim strSQL As String
  4.   strSQL = "SELECT FCG10.person1 FROM FCG10;"
  5.  
  6.   Set dbs = CurrentDb()
  7.   Set rst = dbs.OpenRecordset(strSQL, dbOpenSnapshot)
  8.  
  9.   Do While Not rst.EOF
  10.     If IsNull(rst!person1) Then
  11.         longUncontacted = longUncontacted + 1
  12.     Else
  13.         longGuinta = longGuinta + 1
  14.     End If
  15.   rst.MoveNext
  16.   Loop
  17.   rst.Close
  18.   dbs.Close
  19.   Set rst = Nothing
  20.   Set dbs = Nothing

6 1714
Jim Doherty
897 Expert 512MB
Hello Anduril12 :)

I am not sure I quite understand the actual specifics intentions of your code post. My assumption (and I may well be wrong in my interpretation) is that you want to examine a column named 'person1' in a table called FCG10 and then loop down that column to apply some logic as posted to increment your variables+1

I see you framing of your code is inclined towards looping for each field but what is the point if you know the name of the column? Why not just call that individual column as a 'single column' dataset ie not drag up the entire table.

The following is my interpretation of what I 'think' you are trying to do

Expand|Select|Wrap|Line Numbers
  1.  Dim dbs As DAO.Database
  2.   Dim rst As DAO.Recordset
  3.   Dim strSQL As String
  4.   strSQL = "SELECT FCG10.person1 FROM FCG10;"
  5.  
  6.   Set dbs = CurrentDb()
  7.   Set rst = dbs.OpenRecordset(strSQL, dbOpenSnapshot)
  8.  
  9.   Do While Not rst.EOF
  10.     If IsNull(rst!person1) Then
  11.         longUncontacted = longUncontacted + 1
  12.     Else
  13.         longGuinta = longGuinta + 1
  14.     End If
  15.   rst.MoveNext
  16.   Loop
  17.   rst.Close
  18.   dbs.Close
  19.   Set rst = Nothing
  20.   Set dbs = Nothing
May 8 '10 #2
@Jim Doherty

Thanks, that works perfectly! I sincerely appreciate your help, it wasn't exactly where I was going (I didn't even know that you could call up a single column) but it's great!

~anduril
May 9 '10 #3
Jim Doherty
897 Expert 512MB
Yes you can :) It is a fundamental part of calling any recordset namely to proclaim the bounds of your dataset. I wish more people were considering of this instead of opening entire tables every time. It might reduce the moans much later about performance hits and memory loss through lack of foresight........just my two cents worth...rant end hahaha

Glad it helped you :)
May 9 '10 #4
NeoPa
32,556 Expert Mod 16PB
The error message is the clue here SwordMan.

For ... Each constructs work only for arrays and object collections. A recordset doesn't equate to a collection (which are typically held internally rather than remotely on disk).

Jim has already shown how Recordsets should be manipulated, and given some further good explanations with it, so I won't go there. I just wanted to explain exactly why you got your error message.
May 9 '10 #5
@NeoPa That makes a whole lot of sense! I'm glad that I understand how it really works now, I think that this will help me allot in my future usage. Thank you both so much, I was so completely stuck.
May 9 '10 #6
NeoPa
32,556 Expert Mod 16PB
You're most welcome.

BTW I've selected the best answer for you :)

Welcome to Bytes!
May 10 '10 #7

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

Similar topics

3
by: undercups | last post by:
When I run page I immediatley get "Object expected" message and the tag <body onload="setfocus()" is highlighted. The error occurs in this snippet from within the script file function...
2
by: JMCN | last post by:
help! i'm caught in the endless of "compile error message: do without loop." i thought that i closed all of my statments but it appears not. does anyone know why my structure is incorrect? what...
1
by: SJ | last post by:
I'm developing a WAP client which presently works fine on most mobile phone browsers, but gives me an Infinite loop error (error 1025) when i try to access it from a couple of phones(motorola for...
8
by: Sheldon | last post by:
Hi, I have a problem that and the answer eludes me: I am converting a 2D array to a 1D array within a for loop that looks something like this: ii=0; for (i = 0; i < 300; i++) { for (j =...
5
Reika
by: Reika | last post by:
Hey there, I posted once before with help and everyone did a good job guiding me. I come now with another C++ question, using CodeWarrior 5 I'm making a tic tac toe game. The stage I am at now...
11
by: orajit | last post by:
---When I run following code DECLARE v_evct NUMBER(20); v_evcd NUMBER(20); v_class VARCHAR2(100); cursor c1 is select * from input_info; BEGIN
5
by: Poly | last post by:
Here is a block of code that I am having trouble with. I rewrote it as a main function, so I could isolate the problem to fix it, but still haven't been able to figure out the problem. I am pretty...
2
by: Darkside12 | last post by:
Hi, I'm trying to create a do loop that renames files in a folder. My current code looks like this: Private Sub Rename_Files_Click() Dim VPNPath As String VPNPath = Dir("C:\Temp\*.txt")
0
by: if1467 | last post by:
Hi, I am working with a loop that has the .Find method in it. I need to figure out how to have the program continue when the find doesn't find anything. The VB Help for Find Method shows the...
2
by: rando1000 | last post by:
I keep getting a compile error, "Loop without Do". I've tried Do While and Do Until. What am I doing wrong here? I've got other pieces of code like this in my project, and they work fine. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
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,...
0
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...

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.