Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Mar 2002
    Thanked 0 Times in 0 Posts

    Screen Saver (Access 2000)

    Anyone know how to start the scrren saver with VBA code?

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Silicon Valley, USA
    Thanked 94 Times in 90 Posts

    Re: Screen Saver (Access 2000)

    I haven't reviewed this code recently; it's not very elegant looking, but it seems to work. Important: This uses Word-specific objects (System). To use this code in Access you will need to set a reference to the Word object library or substitute Windows API calls.
    <pre>Sub SecureNow()
    'jfsSecureNow - Starts the screen saver immediately
    'Created 03/07/95, Jefferson F. Scher
    'Converted 6/14/99; updated for Windows NT/2000 10/3/01

    Dim strScrnSaver As String, strMsg As String
    Dim intHandle As Double

    'Retrieve name of current screen saver from system.ini
    'append command switch (otherwise you get the
    'configuration dialog), and then shell to it
    strScrnSaver = System.PrivateProfileString("system.ini", "Boot", "SCRNSAVE.EXE")
    If strScrnSaver = "" Then 'user does not have a screen saver set up
    If System.OperatingSystem = "Windows" Then
    strScrnSaver = "c:windowssystem3dflow~1.scr"
    ElseIf System.OperatingSystem = "Windows NT" Then
    strScrnSaver = "c:winntsystem32ssmyst.scr"
    'cannot do
    Exit Sub
    End If
    strMsg = "I realize you hadn't selected that screen saver, but I had to pick " & _
    "something! If you want to choose a different screen saver, right click on " & _
    "your desktop, choose Properties, and then click the Screen Saver tab."
    End If
    strScrnSaver = strScrnSaver + " /s"

    On Error GoTo Oops
    intHandle = Shell(strScrnSaver)
    On Error GoTo 0

    If strMsg <> "" Then
    MsgBox prompt:=strMsg, buttons:=vbInformation + vbOKOnly, Title:="Mea Culpa"
    End If
    GoTo bye

    On Error GoTo 0
    MsgBox prompt:="Not able to start screen saver. " & _
    "Check your settings in the Display Control Panel."

    End Sub</pre>

  3. #3
    Gold Lounger
    Join Date
    Feb 2001
    Dublin, Ireland, Republic of
    Thanked 0 Times in 0 Posts

    Re: Screen Saver (Access 2000)

    Try <pre>Private Declare Function GetActiveWindow Lib "user32" () As Long
    Declare Function SendMessage Lib "user32" _
    Alias "SendMessageA" ( _
    ByVal hwnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    ByVal lParam As Long) As Long

    Const WM_SYSCOMMAND = &H112&
    Const SC_SCREENSAVE = &HF140&</pre>

    and use the following to invoke it <pre> Call SendMessage(GetActiveWindow(), WM_SYSCOMMAND, SC_SCREENSAVE, 0)</pre>

    Andrew C

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts