Link to home
Start Free TrialLog in
Avatar of Member_2_7966563
Member_2_7966563

asked on

Endless loop in MS Access VBA. Need to interrupt and enter debug mode

My MS Access VBA is stuck in an infinite loop. My keyboard does not have a Break key. How can I interrrupt the execution and enter Debug mode?
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Ctrl+F14  ?
From the web.

Ctrl + Fn + F11 or Fn + B or Fn + Ctrl + B on certain Lenovo laptops.
Ctrl + Fn + B or Fn + B on certain Dell laptops.
Fn + Esc on Samsung.
Ctrl + Fn + ⇧ Shift on certain HP laptops.
Avatar of Member_2_7966563
Member_2_7966563

ASKER

Thanks Martin. I tried them all, but none worked
What kind of computer do you have? Can you show a picture?
It is Lenovo Yoga X1. But the OS also has an on screen keyboard (Win 10) if I need any other keys (Break key is also not present there)
Often when in tight loops even Break doesn't work. You could always quit Access or reboot and when you restart Access you can add a breakpoint somewhere in the code and use F8 repeatedly to step through the code. Please see this article of mine for more information about debugging. Don't be put off by the fact it talks about VB6. VBA is very similar.
I generally add a DoEvents line whenever I have a loop like this:

While somecriteria = true

     DoEvents

     'your other code here

Wend

Open in new window

This returns control to Windows to process other actions during each pass through the loop.  Which should free up your computer to process the Control key sequences mentioned by Martin.
Hi Dale, my loop already had a DoEvents, but I still faced the problem
ASKER CERTIFIED SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
How about showing us the code?
I added a DoEvents right after the Do statement, and that made the program responsive to keystrokes again. Ctrl + Pause worked for me (had to keep it pressed continuously).

That's strange, because although my DoEvents was embedded within an If and EndIf statement, I am pretty certain that the If condition was always true, or the loop would have been exited.

Thanks for your help.
Glad to help.

You probably don't have to keep it pressed, the Ctrl+Pause keystrokes should be stored in your keyboard buffer.  It is probably just that the processing that goes on during each pass through the loop takes longer than you would expect.

Try starting the process, then press Ctrl+Pause once and just wait to see if it is working.  You might want to insert a loop counter and debug.print right before your DoEvents command, that would help you determine which pass you are on in the loop when you press the Pause and when it actually breaks.

Dale
Hi Dale,

What worked the other day is not working today :(. it is still the same code and I am trying the same keystrokes to interrupt, but it just wont respond....

One of the commands is to open an external linked table (Sharepoint) that is on a remote server. Could it be that this command is taking too long to execute and there is no way to interrupt this command?
Put a DoEvents directly after the line that opens the external linked table.
That could have something to do with it.

One of the things about running processes in a loop is that once a particular process (setting a recordset based on a query) is begun, you cannot interrupt the process until that particular step is completed, which is why I generally put my DoEvents line at the beginning of each loop.

Is there a reason for opening this Sharepoint table (I assume you mean creating a recordset from the table) inside the loop instead of outside the loop?  It would be helpful if you shared your code, so we could identify inefficiencies in the looping process.

Dale
Putting the DoEvents directly after the line that opens the external linked table should allow the opening to complete before the code moves on.