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? - Do While cnt < 89 'Number of tables
-
strCurrName = rs("Name")
-
With dbs
-
strSQL = "Insert into FullTable Select * from " & strCurrName
-
.Execute strSQL
-
End With
-
-
strCurrTab = Replace(Left(strCurrName, InStr(strCurrName, "_")), "_", "")
-
-
With dbs
-
strSQL = "Update FullTable Set Tab = '" & strCurrTab & "' where Isnull(Tab)"
-
.Execute strSQL
-
End With
-
-
With dbs
-
strSQL = "Insert into FullTable Select * from Divider"
-
.Execute strSQL
-
End With
-
-
cnt = cnt + 1
-
rs.MoveNext
-
Loop
8 2298
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)>
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.
No luck. Still, toward the end of the file, records from various source tables are intermingled.
Is there any way to disable asychronus behavior?
On second hand, I take that back. It does seem to have worked. Thanks much!
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. - Public Function Wait(lngSeconds As Long)
-
Static bRunning As Boolean
-
Dim dtEnd As Date
-
-
If Not bRunning Then
-
bRunning = True
-
dtEnd = DateAdd("s", lngSeconds, Now())
-
Do Until Now() >= dtEnd
-
DoEvents
-
Loop
-
End If
-
bRunning = False
-
End Function
Linq ;0)>
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.
Glad we could help!
Linq ;0)> Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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
|
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...
| |
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
|
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...
|
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.
...
|
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...
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |