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 6892
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...
|
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. ...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |