DoEvents (1 Viewer)

Wuff

New member
Local time
Today, 15:33
Joined
Sep 17, 2002
Messages
8
DoEvents !!!!!!!! Duh !

Ya know, sometimes things just don't click ? I missed a major turn on this one. I don't have a clue how "DoEvents" is used, even tho I have read till I am blue in the face ! It just does not turn the little light on for me. Duh !

I understand it turns loose, so I can click on the form and I am using a timer around it.


I am running a loop 24/7 and need to be able to stop it if we are not using the program. I start it with a form check box and when I try to use same box or another box to stop it... it hollers about my macro or function being updated or trying to save...

I just don't understand what goes along with the "DoEvents" line. What other lines are associated with the "DoEvents"? Can anyone explain the "DoEvents" differently that all the help comments? Guess I need it in dummy words, even tho I do have a fairly good understanding of vb an access.

I call the loop from the check box, which calls a macro to call a function that runs the loop. Sheesh, I am getting so goofy on this that I am not making much sense ! LOL

-----------------------------------------------------------
Private Sub AutoON_Click()
Dim PauseTime, Start, Finish, TotalTime
Dim aon As Integer
aon = Forms!AutoA!AutoON
Do While aon = -1
PauseTime = 5
Start = Timer
aon = Forms!AutoA!AutoON
Do While Timer < Start + PauseTime
DoEvents
Loop
Finish = Timer
TotalTime = Finish - Start
aon = Forms!AutoA!AutoON
Forms!AutoA!AutoON.SetFocus
Loop
End Sub
-----------------------------------------------
This runs fine, until I hit the button again. Then I get the following message.

"The macro or function set to the BeforeUpdate or ValidateRule property for this field is preventing MicroSoft from saving the data in the field."
 
Last edited:

Elana

Registered User.
Local time
Today, 13:33
Joined
Apr 19, 2000
Messages
232
I'm not sure you need a DoEvents line in this code. Here is an explanation of DoEvents from the VBA2000 Handbook by Suzann Novalis:

"There are two kinds of processes in Access:

. Processes that send and receive Windows messages to and from the Access objects
. Processes that do not send and receive Windows messages.

For example, Access sends keyboard input and mouse clicks to Windows as messages, but VBA code that manipulates database objects does not send messages.

When VBA is running a procedure, it uses processor time, and Windows may not be able to process the messages it receives in a timely fashion. The unprocessed messages line up in a queue waiting to be processed. In addition, keystrokes line up in a SendKeys queue.

One solution to the problem of unprocessed messages and keys is to use the DoEvnets function to pass control to Windows so that the waiting messages and keys can be processed. When you use the DoEvents function, control is not returned to Access until Windows has finished processing the messages in the queue.

Normally, you include a DoEvents function in a loop that takes a long time and use the function to yield control only occasionally."

Doesn't look to me like your code takes a lot of time to run, so just take the DoEvents out of the code.

I'm not sure why you are generating the error message when you click the button a second time. If you posted your form and code, it might help us to figure it out.

HTH
E
 

Wuff

New member
Local time
Today, 15:33
Joined
Sep 17, 2002
Messages
8
Dear Elana, thanks for your reply. I have posted the same post under General Discussion and forgot to remove this one. Sorry !
I think the Doc figured out the problem on the other post. If you have time, you might read it.

I will delete this post soon.
 

Users who are viewing this thread

Top Bottom