Connecting Tech Pros Worldwide Help | Site Map

delay code from executing while previously ordered actions are still being executed

Newbie
 
Join Date: Oct 2009
Posts: 9
#1: 4 Weeks Ago
This question is an outgrowth of my previous question regarding why a certain textbox wasn't updating. What happens is an addquery is called to add a record to a table and then a textbox (called Total) is set equal to a subtotal textbox (called subtotal2) calculated off that table. The problem is, the Total box reflects the Total before the new item was added. If I then manually tell it to update again a moment later it gives the correct value. So I need a code that will pause execution for a few milliseconds after the addquery is called but before the code Me.Total = Me.Subtotal2 is executed.

Here is the code:
Expand|Select|Wrap|Line Numbers
  1.     stDocName = "AddTransaction"
  2.     DoCmd.OpenQuery stDocName, acNormal, acEdit
  3.     Me.OrderSubform.Requery
  4. ' Pause is needed here'
  5.     Me.Total = Me.Subtotal2
best answer - posted by etmanage
I found the solution elsewhere, here it is:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  4.  
  5. Sub Wait(Sec As Double)
  6.   For i = 1 To Sec * 100
  7.     DoEvents           ' handle events
  8.     Sleep (10)          ' suspend process without CPU-Load
  9.   Next
  10. End Sub
Then where you want to pause you just put
Expand|Select|Wrap|Line Numbers
  1. Wait(seconds)  'where seconds is a number
Newbie
 
Join Date: Oct 2009
Posts: 9
#2: 4 Weeks Ago

re: delay code from executing while previously ordered actions are still being executed


I found the solution elsewhere, here it is:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  4.  
  5. Sub Wait(Sec As Double)
  6.   For i = 1 To Sec * 100
  7.     DoEvents           ' handle events
  8.     Sleep (10)          ' suspend process without CPU-Load
  9.   Next
  10. End Sub
Then where you want to pause you just put
Expand|Select|Wrap|Line Numbers
  1. Wait(seconds)  'where seconds is a number
Reply

Tags
access, pause, vba


Similar Microsoft Access / VBA bytes