Solved

Creating a VBA update loop in Access

Posted on 2010-09-21
6
631 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

740 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