Reputation: 5968
I have a VBA code on Access.
I use the function RunSavedImportExport using a saved import specification. Basically it imports a CSV file and puts it in a table let's call it Table_A.
Right after importing the file I have an SQL query on Table_A.
When running the code, it fails on the SQL query saying that Table_A is not found and stops at this line. If I hit again run, it continues whithout any issue.
It seems like the code moves to the second instruction while the importation has not finished yet.
Has anyone had a problem like this ?
Thanks.
Upvotes: 2
Views: 275
Reputation: 1502
I have not had this specific problem before, but a similar circumstance where I can only describe it as "the code moved too fast".
Try adding a delay between creating the table and querying from it. Access doesn't allow application.wait
so you could try the following:
Dim T1 As Variant
Dim T2 As Variant
T1 = Now()
T2 = DateAdd("s", 1, T1)
Do Until T2 <= T1
T1 = Now()
Loop
This does add a one second delay, so hopefully the time length isn't an issue for yourself.
EDIT
from what @Andre has suggested in the comment, I understand this to be a smarter alternative to my delay suggestion.
option explicit
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
function RunSavedImportExport()
[some code]
Dim T1 As Variant
Dim T2 As Variant
T1 = Now()
T2 = DateAdd("s", 1, T1)
Do Until T2 <= T1
T1 = Now()
sleep 50
Loop
[some code]
end function
Upvotes: 1