Solved

TEmporarily stop code in VBA

Posted on 2012-04-02
7
569 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

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…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

821 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