I have seen this issue posted a huge amount of times so I am going to post how to resolve this issue.
Access does not have any type of wait, pause or sleep functions. So the question is always, "How do I make Access VBA wait for some length of time before going on?"
The typicall answer is to create a loop such as:
While this does take time to process it is unreliable and may result in an error. VBA does have the proper tools to be able to create a wait.
First we have to establish the time that it is now - TWait = Time.
Next we have to determine how long we want to wait. I am using the DateAdd function to add 15 seconds to TWait. For more on the DateAdd funtion use help in Access.
Now, we need to prevent the VBA coding from moving to the next block of code and for that we are using the loop. The Do Until loop does just that, it loops until TWait is greater than or equal too TNow. Each time through the loop the current time is evaluated and then compared to our wait time and if the time to now is not greater than the wait time the code will loop again.
I had to add the greater than to the loop because I found that the time only displays in HH:MM:SS this is not the case for the variable so if the time passes then it is ok to move on.
I had to use this to make Access VBA wait while I was trying to send keystrokes to another program. There is a download lag that I needed to wait until it was complete before I could send the next set of keys. I have not had an issue with this option for waiting.
Hope you find this helpful.
Access does not have any type of wait, pause or sleep functions. So the question is always, "How do I make Access VBA wait for some length of time before going on?"
The typicall answer is to create a loop such as:
Code:
For i = 1 to 10000000
Next
While this does take time to process it is unreliable and may result in an error. VBA does have the proper tools to be able to create a wait.
Code:
TWait = Time
TWait = DateAdd("s", 15, TWait)
Do Until TNow >= TWait
TNow = Time
Loop
First we have to establish the time that it is now - TWait = Time.
Next we have to determine how long we want to wait. I am using the DateAdd function to add 15 seconds to TWait. For more on the DateAdd funtion use help in Access.
Now, we need to prevent the VBA coding from moving to the next block of code and for that we are using the loop. The Do Until loop does just that, it loops until TWait is greater than or equal too TNow. Each time through the loop the current time is evaluated and then compared to our wait time and if the time to now is not greater than the wait time the code will loop again.
I had to add the greater than to the loop because I found that the time only displays in HH:MM:SS this is not the case for the variable so if the time passes then it is ok to move on.
I had to use this to make Access VBA wait while I was trying to send keystrokes to another program. There is a download lag that I needed to wait until it was complete before I could send the next set of keys. I have not had an issue with this option for waiting.
Hope you find this helpful.