Stop PC going to Monitor Powersave using vba

noboffinme

Registered User.
Local time
Tomorrow, 00:15
Joined
Nov 28, 2007
Messages
288
Hi

I am using an extra PC & want the PC to stay awake while it runs a query.

I thought I'd get the computer to hit the keyboard letter 'A' after 5 minutes to make sure it doesn't go turning off the monitor using the 'Sendkeys' method.

So I've got a repeating timer procedure but I'm unsure whether this is the right approach.

The result is that I get the timer to add the 'A' letter only once when really I need it to repeat this action every 5 minutes to keep the PC 'awake' so it's similar to me hitting the letter 'A' every 5 mins.

Any suggests?

-------------------------------------------

Option Explicit
Public RunWhen As Double
Public Const cRunIntervalSeconds = 300 ' five minutes
Public Const cRunWhat = "TheSub" ' the name of the procedure to run

-------------------------------
Sub StartTimer()

RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
Schedule:=True

End Sub

---------------------------

Sub TheSub()

Application.SendKeys "{A}"

StartTimer ' Reschedule the procedure

End Sub
---------------------------
 
For a start 300 <> 5 mins

1000 = 1 second

Also can you not set the computer settings not to go to sleep

And can you be sure that sendkeys actually wakes up a computer?
 
Hi DCrake

I've tested the number figure in this code & using '5' = 5 seconds for example & it does work but this detail is not so important to get this proc to repeat (which is my question)

I've already tried changing the settings & that's why I am trying vba.

No I can't be sure if Sendkeys will wake up my PC & this is why I'm on this forum.

Now, as I've answered your questions about my questions, can you actually suggest an answer?
 
I take it that this machine simply has a db on it that sits there doing nothing except running queries based on a timer interval, without human intervention?

What you can do is to detect idle time. This means having a hidden form open that sits there waiting for someone to hit the keyboard or press the mouse. Do a search her on DetectIdleTime.

When you reach the desired idle time, instead of closing a form or doing something else you could then do the sendkeys action.

If the db is operating in some other method then an explanation is required.
 
That's right,

The code will operate by itself, I found the reference to a post about DetectIdleTime, Thanks
 
Hi

I am using an extra PC & want the PC to stay awake while it runs a query.

I am not sure you can run another function in the same database while the query is proccessing. Access has a problem with doing more than one thing at a time.

I would be interested in this if you get it to work for I have a database that outputs a huge pdf file in Access 2007 but the report creation is stopped when the screen saver comes on which is every ten minutes unless I wiggle the @#$%^&* mouse before that happens.
 
Interesting way to detect idle time.

If the computer has Admin priviledges then you can set the power config settings using Shell. That is, set it to high performance (for example) and you would have already manually set the properties of that setting to stay on before running the code. Set the power setting back to the previous value after the code runs (plus set it back if it errors too).

If you wish, you can look into powercfg -s

For help powercfg -?
 

Users who are viewing this thread

Back
Top Bottom