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

Home Posts Topics Members FAQ

Loop through all records in a table

7 New Member
Hello All--

I am trying to loop through all the records in a table named: tbl_Scan_Index. I am using MS Access 2003. Here is my code(VBA):


Expand|Select|Wrap|Line Numbers
  1. Dim drawer As Integer
  2. Dim Folder As Integer
  3. Dim msg As String
  4. Dim count As Integer
  5.  
  6. drawer = 11
  7. Folder = 1
  8.  
  9. Dim DB As Database
  10. Dim rst As DAO.Recordset
  11.  
  12. Set DB = CurrentDb()
  13. Set rst = DB.OpenRecordset("tbl_Scan_Index")
  14.  
  15. rst.MoveLast
  16. rst.MoveFirst
  17. While Not rst.EOF
  18. If Me.Folder_Num.Value = Folder Then
  19.         count = count + 1
  20. End If
  21. Wend
  22.  
  23. msg = MsgBox(count, vbOKOnly)
My goal is to loop through all of the records, and count the number of records where Folder_Num (field in table) is equal to 1. I get an overflow error, and the counter goes way over the number of records that are in the table. Any ideas as to why? I am very new to DOA, and access programming. Thanks in advance.
Apr 3 '08 #1
6 6892
blad3runn69
59 New Member
maybe try a DCount function like
intX = DCount("[Folder_Num]", "tbl_Scan_Index", "[Folder_Num] = 'Folder'")

welcome 2 bytes :)
Apr 4 '08 #2
blad3runn69
59 New Member
maybe try a DCount function like
intX = DCount("[Folder_Num]", "tbl_Scan_Index", "[Folder_Num] = 'Folder'")

welcome 2 bytes :)
sorry

intX = DCount("[Folder_Num]", "tbl_Scan_Index", "[Folder_Num] = 1")
Apr 4 '08 #3
MikeTheBike
639 Recognized Expert Contributor
Hi

I agree with blade3runner69 regarding that DCount() is the method of choice (or perhaps "SELECT Count([Folder_Num]) As Count FROM tbl_Scan_Index WHERE [Folder_Num] = 1" for very large tables), I think, for the record, the error in the code should be noted/corrected ie.


Dim drawer As Integer
Dim Folder As Integer
Dim msg As String
Dim count As Integer

drawer = 11
Folder = 1
Expand|Select|Wrap|Line Numbers
  1. Dim DB As Database
  2. Dim rst As DAO.Recordset
  3.  
  4. Set DB = CurrentDb()
  5. Set rst = DB.OpenRecordset("tbl_Scan_Index")
  6.  
  7. rst.MoveLast
  8. rst.MoveFirst
  9. While Not rst.EOF
  10.     If rst("Folder_Num") = Folder Then
  11.         count = count + 1
  12.     End If
  13.     rst.MoveNext
  14. Wend
  15.  
  16. msg = MsgBox(count, vbOKOnly)
??

MTB
Apr 4 '08 #4
kwstriker299
7 New Member
Thanks guys!!!

Your suggestions worked wonderfully!!! Its good to know there is a place where I can come if I have questions. Your help is much apprecited :)
Apr 4 '08 #5
kwstriker299
7 New Member
Another question,

If i use the DCount() methode like this:

DCount("[Folder_Num]", "tbl_Scan_Index", "[Folder_Num] = 1")

It works fine, and returns the correct result. Is there any way that it can be used with a variable (folder) instead of hard coding [Folder_Num] = 1. I would like to be able to increment the folder.

Thanks in advance!!!
Apr 4 '08 #6
pdebaets
16 New Member
Try:

DCount("[Folder_Num]", "tbl_Scan_Index", "[Folder_Num] = " & folder)
Apr 4 '08 #7

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

Similar topics

12
by: jason | last post by:
Access 2000: I have a customer-inventory table I need to loop through and compile a list of all the inventory items the customer is tracking. The problem I am finding is that a simple loop...
2
by: JC | last post by:
Hi, I have a database that imports 4 reports to my "data" table, each report has its own identifier. Then I have a table with Analysts with the report identifier that they are to be assigned to. ...
20
by: Steve Jorgensen | last post by:
Hi all, I've just finished almost all of what has turned out to be a real bear of a project. It has to import data from a monthly spreadsheet export from another program, and convert that into...
1
by: David | last post by:
Hi, I'm having trouble copying table data to new records. I have two tables as follows: *** Specifications (Table) specification_ID (field) LINKED product_ID (field) specification_header...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
2
by: chalrav | last post by:
Hi, I have three tables as below: Table: Demand ITEM_ID, QUANTITY Item A, 10 Table: Route ITEM_ID, OPERATION_NO, RESOURCE, TIME
8
by: SaltyBoat | last post by:
Needing to import and parse data from a large PDF file into an Access 2002 table: I start by converted the PDF file to a html file. Then I read this html text file, line by line, into a table...
22
by: kjworm | last post by:
Greetings everyone, I am working on a scheduling tool and have a temp table that I am attempting to loop through to pull the necessary info out of before deleting. I am using Access '97 on...
2
by: farouqdin | last post by:
Hi all i have code which loops through table and deletes the duplicate records. This code does it for one table. How do i change it so it goes through several tables? On Error Resume Next Dim...
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,...
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...
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: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.