Solved

TEmporarily stop code in VBA

Posted on 2012-04-02
7
564 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
7 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 75
ID: 37798867
You are welcome ...

mx
0
 
LVL 57
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 57
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The canonical version of this article is on my web site here: http://iconoun.com/articles/collisions/ A companion presentation is available here: http://iconoun.com/articles/collisions/Unicode_Presentation.pdf
The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now