?
Solved

Creating a VBA update loop in Access

Posted on 2010-09-21
6
Medium Priority
?
640 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 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 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 48

Expert Comment

by:Dale Fye
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
Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

 
LVL 85
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 48

Expert Comment

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

Featured Post

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.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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…
Suggested Courses

770 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