Solved

Creating a VBA update loop in Access

Posted on 2010-09-21
6
593 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
Comment Utility
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)
Comment Utility
Can you post the SQL that give that error, we might be able to identify your problem for you.
0
 

Author Comment

by:hwassinger
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 84
Comment Utility
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
Comment Utility
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)
Comment Utility
so, what was your final solution on this?
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now