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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open MS Publisher from Access Form 1

Status
Not open for further replies.

evalesthy

Programmer
Oct 27, 2000
513
US
I have a Publisher document that has an Access data source. I would like to be able to print the Publisher document from a command button on an Access form and then have it close. An alternative would be to open it in Preview mode and allow the user to print & close the Publisher document. Can someone suggest proper script. Also, I assume I will need to reference the Publisher Object Library.

I did not post this in the Publisher Forum as there appears to be very little activity there.
 
Have you tried to play with the FollowHyperlink method ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
first you can take this module save it as a moudle named fHandel

Code:
Option Compare Database

Private Declare Function apiShellExecute 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 Const WIN_NORMAL = 1         'Open Normal
Public Const WIN_MAX = 2            'Open Maximized
Public Const WIN_MIN = 3            'Open Minimized

Private Const ERROR_SUCCESS = 32&
Private Const ERROR_NO_ASSOC = 31&
Private Const ERROR_OUT_OF_MEM = 0&
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_BAD_FORMAT = 11&

Function fHandleFile(stFile As String, lShowHow As Long)
Dim lRet As Long, varTaskID As Variant
Dim stRet As String
    'First try ShellExecute
    lRet = apiShellExecute(hWndAccessApp, vbNullString, _
            stFile, vbNullString, vbNullString, lShowHow)
            
    If lRet > ERROR_SUCCESS Then
        stRet = vbNullString
        lRet = -1
    Else
        Select Case lRet
            Case ERROR_NO_ASSOC:
                'Try the OpenWith dialog
                varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " _
                        & stFile, WIN_NORMAL)
                lRet = (varTaskID <> 0)
            Case ERROR_OUT_OF_MEM:
                stRet = "Error: Out of Memory/Resources. Couldn't Execute!"
            Case ERROR_FILE_NOT_FOUND:
                stRet = "Error: File not found.  Couldn't Execute!"
            Case ERROR_PATH_NOT_FOUND:
                stRet = "Error: Path not found. Couldn't Execute!"
            Case ERROR_BAD_FORMAT:
                stRet = "Error:  Bad File Format. Couldn't Execute!"
            Case Else:
        End Select
    End If
    fHandleFile = lRet & _
                IIf(stRet = "", vbNullString, ", " & stRet)
End Function

Then the command bustton should have the on click error a line like this

Code:
fHandleFile "exact location of your file", WIN_NORMAL

where i wrote the text exact location of file type the exact directory (i.e. "C:\Files\Database\test.mdb")

type the lines in " "


I will try my best to help others so will others do!!!!!
IGPCS
Brooklyn, NY
 
Thanks for the suggestions. I put IGPCS's code in place and it is a great starting point. The Publisher document opens in design view. Now I need to show my ignorance in working in Publisher. When I open the pub doc from my Access command button I would like to have it open in Preview showing the data that is going to be inserted from my datasource (an Access table or query). Note: The inserted data does print correctly if I print the publisher doc from the toolbar. Alternatively, if the data cannot be shown in preview then I would prefer to go directly to print.

Also, when the document opens it always has a warning message "Opening this publication will access data from the following location: ......." Is there a way to suppress this warning - the users whole intent is to attach the linked data.

Thanks again. Sorry for my late reply - I was away dealing with a family medical issue.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top