Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I turn off monitor with vba? 1

Status
Not open for further replies.

LonnieJohnson

Programmer
Apr 16, 2001
2,628
US
Does anyone know if code to use an api to turn off a monitor?

ProDev, Builders of Affordable Software Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
This may be of interest:

Code:
Option Explicit
Private Declare Function SendMessage Lib _
"user32" Alias "SendMessageA" (ByVal hWnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long


Const SC_MONITORPOWER = &HF170&
Public Const MONITOR_ON = -1&
Public Const MONITOR_OFF = 2&
Const WM_SYSCOMMAND = &H112

'Turn Monitor on:
'SendMessage Application.hWndAccessApp, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_ON
'
'Turn Monitor off:
'SendMessage Application.hWndAccessApp, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF

Sub TheSub()
    SendMessage Application.hWndAccessApp, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF
End Sub

 
Thanks. This seems to work. However my monitors come back on after about two seconds. Not sure if it has something to do with the dual monitors.

ProDev, Builders of Affordable Software Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
Lonnie, shouldn't have thought this was a problem caused by the dual monitors. I've used similar code (admittedly from VB6 rather than access) in the past on dual monitors with no problems.

Is there anything happening on your machine that would cause the monitor to become active again (for example the mouse moving, not that I'm thinking you're moving the mouse just an example). The reason I ask is that turning the monitor off in this way is essentially putting it into powersaving mode (though in powersaving mode there is a STANDBY message sent before the OFF message) and therefore the monitor has the ability to be fired back into life quite easily.

Hope this helps

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
Definitely sounds interesting.

Can I ask why you'd need to do something like this? I'm just curious, b/c I can't think of a reason off-hand with an Access Database.

--

"If to err is human, then I must be some kind of human!" -Me
 
Lonnie, to save me typing it there's a bit more information regarding monitor power settings in this link thread222-1546572 (no need to really pay attention to the subclassing part of it).

Hope this helps

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top