Solved

Creating a VBA update loop in Access

Posted on 2010-09-21
6
617 Views
Last Modified: 2012-05-10
I have a table in MS Access with 641,000 records.

When I try to run an update query I receive an error - "not enough space on temporary disk"

I'd like to create a nested loop (i think) that would run the update based on 2 criteria

By location and then date... 2N for for 20100801, then 2N for 20100802 --> 20100831
                                              3N for for 20100801, then 2N for 20100802 --> 20100831
etc...

Any suggestions on how to code this?


A2N
A3NE
A4NE
A4NW
A5ST
A6ST
A7ST
ACCU
AED
ALD
AMBU
ANBU
AOU
APED
ASCN
BED
BICU
BMSU
BPCU
M3N
M3S
M4N
M4S
MED
MICU
MPCU
V2B
V4G
V4O
V5B
V5O
V6B
V6O
VED
VICU
VINF
VMB3
VMB4
VMSW
VNEO
VNU3
VNU4
VPCU
VPED
VPIC
0
Comment
Question by:hwassinger
6 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 33725258
The best way to update a table is by using straight SQL. I'm not sure what your criteria would be, but this is the basic method:

Currentdb.Execute "UPDATE MyTable SET Field1='SomeValue', Field2=1234 WHERE Field3='MyFilterCriteria'"

If you can further define what/how to filter we can look further
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 33725392
Can you post the SQL that give that error, we might be able to identify your problem for you.
0
 

Author Comment

by:hwassinger
ID: 33725421
Running it in SQL would be ideal but its just too many iterations to do manually.

Table 1 has the location (45 records)
Table 2 has the date 20100801 thru 20100831 (600,00 records)

So what I need is a loop that says

Select Location from table 1
For date = 20100801 thru 20100831  DO UPDATE phm_mac_chrt_trns, Query5 SET phm_mac_chrt_trns.[TIME] = [Query5]![Time Difference in minutes];

NEXT DATE

When DATE hits 20100831 NEXT Location
for date = 20100801 ...
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 84
ID: 33725548
You don't use iterations in SQL, you allow the "server" to manage that for you - and it's always faster. We'd have to know more about your process however, but if you have 45 Locations, then you can open a Recordset based on that, loop through for each Location (i.e. 45 times) and run an Update query for each. You coudl also use Nested and Grouped queries, but those can sometimes run somewhat slow, and you must be very careful to build them properly in order for them to update properly.

0
 
LVL 3

Expert Comment

by:CvD
ID: 33725911
Easiest solution as I see it:

1. Create a view in the database that for each location contains all date records. My sql knowledge is a bit rusty, but I was thinking of something in the line of: select * from table 1 left outer join table2 on true.

2. Update the view using the sql update statement.
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 33725994
so, what was your final solution on this?
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question