Share via

Shell Execute code

Anonymous
2010-11-27T16:48:08+00:00

Hi,

Iv got the below code in a module, then behind a cmd button on a form i have  ExecuteFile Me.DocLink, "Print" - (me.doclink contains a file path).  This works well, but the document opens, prints, then closes.  Can i stop the document actually opening or being visible if it does?

My module code is:

'Source: http://www.pacificdb.com.au/MVP/Code/ExeFile.htm

Public Const SW_HIDE = 0

Public Const SW_MINIMIZE = 7

Public Const SW_RESTORE = 9

Public Const SW_SHOW = 5

Public Const SW_SHOWMAXIMIZED = 3

Public Const SW_SHOWMINIMIZED = 2

Public Const SW_SHOWMINNOACTIVE = 7

Public Const SW_SHOWNA = 8

Public Const SW_SHOWNOACTIVATE = 4

Public Const SW_SHOWNORMAL = 1

Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _

    (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _

    ByVal lpParameters As String, ByVal lpDirectory As String, _

    ByVal nShowCmd As Long) As Long

Public Sub ExecuteFile(sFileName As String, sAction As String)

    Dim vReturn As Long

    'sAction can be either "Open" or "Print".

    If ShellExecute(Access.hWndAccessApp, sAction, sFileName, vbNullString, "", SW_SHOWNORMAL) < 33 Then

        DoCmd.Beep

        MsgBox "File not found."

    End If

End Sub

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

7 answers

Sort by: Most helpful
  1. HansV 462.6K Reputation points MVP Volunteer Moderator
    2010-11-28T14:30:37+00:00

    If neither

    If ShellExecute(Access.hWndAccessApp, sAction, sFileName, vbNullString, "", SW_SHOWMINNOACTIVE) < 33

    nor

    If ShellExecute(Access.hWndAccessApp, sAction, sFileName, vbNullString, "", SW_HIDE) < 33

    works, you can't hide the window using ShellExecute.

    Note to others: the SW_... constants don't correspond to bit positions, they are just enumerated values 0 ... 9, so you can't combine them using OR.

    0 comments No comments
  2. Anonymous
    2010-11-28T14:18:33+00:00

    Hi,

    Ok, iv spent hours trying to understand this, but cant get anything to work??  Im just a 'beginner' at this, so any further explanation greatly appreciated.

    Iv tried changing the 'SW_SHOWNORMAL' to all options suggested above, and none seem to make any difference?  I can only think im going wrong somewhere? Im just changing the SW_SHOWNORMAL in this line of code in my module:

    If ShellExecute(Access.hWndAccessApp, sAction, sFileName, vbNullString, "", SW_SHOWNORMAL) < 33

    Should i be changing it or adding it elsewhere too??

    0 comments No comments