473,505 Members | 14,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inserting records out of order

80 New Member
I have a VBA program that loops through a table of table names and imports the records from those tables into another table. In some instances (not every time), the inserting gets confused, and I will see some records from one table, then some records from another. It's like one insert process is not completing before another begins. Any idea why this happens?

Expand|Select|Wrap|Line Numbers
  1.  Do While cnt < 89 'Number of tables
  2.     strCurrName = rs("Name")
  3.     With dbs
  4.         strSQL = "Insert into FullTable Select * from " & strCurrName
  5.         .Execute strSQL
  6.     End With
  7.  
  8.     strCurrTab = Replace(Left(strCurrName, InStr(strCurrName, "_")), "_", "")
  9.  
  10.     With dbs
  11.         strSQL = "Update FullTable Set Tab = '" & strCurrTab & "' where Isnull(Tab)"
  12.         .Execute strSQL
  13.     End With
  14.  
  15.     With dbs
  16.         strSQL = "Insert into FullTable Select * from Divider"
  17.         .Execute strSQL
  18.     End With
  19.  
  20.     cnt = cnt + 1
  21.     rs.MoveNext
  22. Loop 
Aug 14 '09 #1
8 2298
missinglinq
3,532 Recognized Expert Specialist
Access is asynchronous in the way it runs commands, which is a fancy way of saying it doesn't wait for one command to complete before running the next command in code, which, as you've apparently found out, can cause timing problems and sometimes cause processes to terminate prematurely..

In your code, just before your Loop command, try placing the command DoEvents. This should yield control to system processes, such as pulling records from one table to another, and allow it to complete before starting the next iteration of this.

This is all based on some records not actually getting imported, as opposed to them not appearing in the same order in the table as they were imported. Have you checked for this possibility? That the records are there, just not in the order you expected? A table in Access is, as some like to say, simply a bucket of data. Order really has little meaning in a table.

Linq ;0)>
Aug 14 '09 #2
rando1000
80 New Member
Thanks. I'll give that a try. It's weird, because it works as expected for the first couple dozen tables. I guess after that point, memory is bogged down and processes are not completing fast enough, so it's starting the next process before the first completes.
Aug 14 '09 #3
rando1000
80 New Member
No luck. Still, toward the end of the file, records from various source tables are intermingled.
Aug 14 '09 #4
rando1000
80 New Member
Is there any way to disable asychronus behavior?
Aug 14 '09 #5
rando1000
80 New Member
On second hand, I take that back. It does seem to have worked. Thanks much!
Aug 14 '09 #6
missinglinq
3,532 Recognized Expert Specialist
Glad we could help, and no, there's no way to 'disable' the behavior, you can only work around it.

Besides DoEvents, for example, if you're opening a form to do something and need the code to wait until you close that form before it continues, you can open the secondary form in Dialog mode. All code in the original form will halt execution until you close the second form.

And then there are some 'wait' or 'sleep' hacks out there. The following one, courtesy of Allan Browne at http://allenbrowne.com/tips.html , lets you call a function and enter a set number of seconds that you your code to halt. Notice that this, too, uses DoEvents.

Expand|Select|Wrap|Line Numbers
  1. Public Function Wait(lngSeconds As Long)
  2.    Static bRunning As Boolean
  3.    Dim dtEnd As Date
  4.  
  5.    If Not bRunning Then
  6.        bRunning = True
  7.        dtEnd = DateAdd("s", lngSeconds, Now())
  8.        Do Until Now() >= dtEnd
  9.            DoEvents
  10.        Loop
  11.    End If
  12.    bRunning = False
  13. End Function
Linq ;0)>
Aug 14 '09 #7
rando1000
80 New Member
I also realized I could simply recreate the table after it's put together using the proper SQL order-by clauses. Now that I know what the issue is, I think I can work around it. Thanks again for pointing that out.
Aug 14 '09 #8
missinglinq
3,532 Recognized Expert Specialist
Glad we could help!

Linq ;0)>
Aug 16 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2034
by: Pushpendra Vats | last post by:
Hi , I am trying to insert records into database. I am trying to write the following code. On button1 click event i am inserting five records and after that i am calling the update method of...
1
1992
by: gouse | last post by:
Hello Friends, In a Table I am inserting more than 50,000 Records one by one. It was taking a lot of time . Is it There any good approach/solution for inserting records more than 50,000 one by one...
7
6606
by: ebindia0041 | last post by:
This is like the bug from hell. It is kind of hard to explain, so please bear with me. Background Info: SQL Server 7.0, Asp.net 1.1 with c# I'm inserting simple records into a table. But one...
9
6908
by: Oonz | last post by:
Hi Friends, How can we insert records in sorted order like consider a table No Name Phone 1 test1 12345 1 test1 23455 2 test2 68638
3
1756
by: veerapureddy | last post by:
Hai everybody, i like to insert some records into database from html form by entering data.my problem is how can i check , whether a record is available in database about a particular...
13
3033
by: imnewtoaccess | last post by:
Hi, I am getting errors while inserting records in one table from another. These are the structures of two tables : file51tm_new RecordType Text
2
3057
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography...
5
2144
by: rando1000 | last post by:
Okay, here's my situation. I need to loop through a file, inserting records based on a number field (in order) and if the character in a certain field = "##", I need to insert a blank record. ...
4
2194
by: GabeM | last post by:
I am trying to insert records from one table to another using the WHILE construct, I have managed to move all of the data with the exception of one concatenated field. I can't figure out how to...
0
7216
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7303
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.