Solved

TEmporarily stop code in VBA

Posted on 2012-04-02
7
574 Views
Last Modified: 2012-04-03
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
Comment
Question by:ssmith94015
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 500 total points
ID: 37798388
I would suggest using the Sleep function:


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

mx
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 37798413
How about if you try Me.Repaint before the DCount line.  That might work.
0
 

Author Closing Comment

by:ssmith94015
ID: 37798644
I knew there was a way to do this, I simply could not remember the phrase.  Thank you

Sandra
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 75
ID: 37798867
You are welcome ...

mx
0
 
LVL 58
ID: 37800730
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
 
LVL 75
ID: 37802232
But Jim, I'm pretty sure that sucks up at least 50%+ of the CPU ....

mx
0
 
LVL 58
ID: 37802368
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question