473,804 Members | 3,308 Online
Bytes | Software Development & Data Engineering Community
+ 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 6923
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
2411
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 will pull out the customer details each time their is an inventory item listed....I need to get the customer out ONCE and list his items....is there an elegant way to do this: Here is the table: Cust-Invent Table
2
2700
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. What I need to do is loop the two tables so that an Analyst is assigned to each record in the "data" table based on the identifier. For example, I have one analyst that needs to be assigned to the "H" report records, one analyst that needs to...
20
2772
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 normalized data. The task is made more difficult by the fact that the structure itself can vary from month to month (in well defined ways). So, I used the SQL-centric approach, taking vertical stripes at a time so that, for instance, for each...
1
1916
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 (field)
52
6360
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 variations(combination of fields), - then act on each group in some way ...eg ProcessRs (oRs as RecordSet)... the following query will get me the distinct groups
2
1820
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
6505
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 using a code loop and an INSERT INTO query. About 800,000 records of raw text. Later, I can then loop through and parse these 800,000 strings into usable data using more code. The problem I have is that the conversion of the text file, using a...
22
2058
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 Windows XP. Here is my code: Private Sub ScheduleParts_Click()
2
3817
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 db As DAO.Database, rst As DAO.Recordset Dim strDupName As String, strSaveName As String Set db = CurrentDb()
0
9579
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10571
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10326
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10075
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9143
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7615
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2990
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.