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. Anonymous
    2010-11-27T23:13:10+00:00

    Try this:

    SW_SHOWMINNOACTIVE Or SW_HIDE

    "NT007" wrote in message news:*** Email address is removed for privacy *** .com...

    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.paci ficdb.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


    Regards, Graham R Seach Sydney, Australia

    0 comments No comments
  2. Anonymous
    2010-11-27T18:59:58+00:00

    See: http://msdn.microsoft.com/en-us/library/bb762153(VS.85).aspx (specifically thenShowCmd [in] scetion)

    I would believe that changing the SW_SHOWNORMAL to (SW_SHOWNOACTIVATE Or SW_SHOWMINNOACTIVE) should open/print the file without switching the focus from your database to the file.

    Give it a try and post back.


    Daniel Pineault, 2010-2011 Microsoft MVP

    http://www.cardaconsultants.com

    MS Access Tips and Code Samples: http://www.devhut.net

    0 comments No comments
  3. HansV 462.6K Reputation points MVP Volunteer Moderator
    2010-11-27T18:43:38+00:00

    I think that would require Windows-level programming; hopefully someone else can help you with that.

    0 comments No comments
  4. Anonymous
    2010-11-27T17:05:44+00:00

    No, this doesnt work for me.  Iv tried it and the application still opens up (to fill the screen),

    Any other suggestions welcome,

    many thanks

    0 comments No comments
  5. HansV 462.6K Reputation points MVP Volunteer Moderator
    2010-11-27T16:51:12+00:00

    Does it help if you change SW_SHOWNORMAL to SW_SHOWMINIMIZED?

    0 comments No comments