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): - Dim drawer As Integer
-
Dim Folder As Integer
-
Dim msg As String
-
Dim count As Integer
-
-
drawer = 11
-
Folder = 1
-
-
Dim DB As Database
-
Dim rst As DAO.Recordset
-
-
Set DB = CurrentDb()
-
Set rst = DB.OpenRecordset("tbl_Scan_Index")
-
-
rst.MoveLast
-
rst.MoveFirst
-
While Not rst.EOF
-
If Me.Folder_Num.Value = Folder Then
-
count = count + 1
-
End If
-
Wend
-
-
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.
6 6923
maybe try a DCount function like
intX = DCount("[Folder_Num]", "tbl_Scan_Index ", "[Folder_Num] = 'Folder'")
welcome 2 bytes :)
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")
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 - Dim DB As Database
-
Dim rst As DAO.Recordset
-
-
Set DB = CurrentDb()
-
Set rst = DB.OpenRecordset("tbl_Scan_Index")
-
-
rst.MoveLast
-
rst.MoveFirst
-
While Not rst.EOF
-
If rst("Folder_Num") = Folder Then
-
count = count + 1
-
End If
-
rst.MoveNext
-
Wend
-
-
msg = MsgBox(count, vbOKOnly)
??
MTB
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 :)
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!!!
Try:
DCount("[Folder_Num]", "tbl_Scan_Index ", "[Folder_Num] = " & folder)
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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...
|
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...
|
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)
|
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
| |
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
|
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...
|
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()
|
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()
|
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,...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |