Solved

TEmporarily stop code in VBA

Posted on 2012-04-02
7
566 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

911 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

19 Experts available now in Live!

Get 1:1 Help Now