Solved

Creating a VBA update loop in Access

Posted on 2010-09-21
6
636 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

734 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