[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 585
  • Last Modified:

TEmporarily stop code in VBA

I have a process taht I want to hesitate for about two seconds before proceeding.  But how would I do that?  That is, Between two lines below, I want the VBA to hestitate before proceeding.

Me.cmdCAR.BackColor = 2858687
'Hesitate here to allow time for the backcolor change on the form
intCount = DCount("UserID", "TblUsers_CAR", "UserID = '" & gstrUserID & "' AND Active = -1 ")

Sandra
0
ssmith94015
Asked:
ssmith94015
1 Solution
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
I would suggest using the Sleep function:


http://access.mvps.org/access/api/api0021.htm

mx
0
 
IrogSintaCommented:
How about if you try Me.Repaint before the DCount line.  That might work.
0
 
ssmith94015Author Commented:
I knew there was a way to do this, I simply could not remember the phrase.  Thank you

Sandra
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
You are welcome ...

mx
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
Sandra,

  You might also want to use the function below.  One of the bad things about sleep is that it puts the thread totally to sleep (no CPU cycles).

   If I need a pause, but want background processing to continue, then I use the function below.

Jim.

Public Function Wait(intSeconds As Integer) As Integer

        Dim datCurDateTime As Date
10      datCurDateTime = Now

20      Do Until DateDiff("s", datCurDateTime, Now) > intSeconds
30        DoEvents
40      Loop

End Function
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
But Jim, I'm pretty sure that sucks up at least 50%+ of the CPU ....

mx
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
mx,

<<But Jim, I'm pretty sure that sucks up at least 50%+ of the CPU ....>>

  I've never really checked, but I don't believe so.   Nothings going on other then the loop.  It might show 50% if you only have two active tasks, but that really is meaningless.  If another thread comes along and wants for processor time, it will get it.

  That's just like a few years ago where Access had a tight loop on the keyboard for 30 seconds.  Often performance monitor would show 100% CPU usage; but the CPU didn't have any other threads contending for it.  Start another thread and it would drop right down.

  The main point to be aware of is that you retain control and have the chance to do something (like check for an abort), while still giving other threads as much time as possible.  With sleep, you are totally dead for that period of time.

  So it depends on what your goal is and what your doing.   That was my only reason for posting; to make Sandra aware of that and the difference.  It may be however that for the task at hand, sleep is be a better choice.

Jim.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now