+ Reply to Thread
Results 1 to 5 of 5

Open PDF from Combo Box in Access

  1. #1
    Registered User
    Join Date
    01-24-2011
    Location
    Minneapolis MN
    MS-Off Ver
    Excel 2007
    Posts
    12

    Open PDF from Combo Box in Access

    OK, so not that long ago I asked a similar question about getting Excel to open, but I can't seem to apply the same theory on opening a PDF. Everything I found in my searches was written in VB or required the use of fields that are already in use.

    So here's my scenario: The current selection in the database is set to open a form via a macro. I want this selection to open a PDF instead as the required form has changed, but we want to cater to the staff and not make them look up the form in a new way or location. I really don't want to redo this form in Access because it loses end-user capabilities (we have to send it to a client). In a sense, the Access database is more of a dashboard for this function.

    The combobox is set that if the title from a table is chosen, an action happens from a macro. Is there a macro I can use to open a PDF?
    If VB is involved, I will need hand-holding. I am in dire need of a VB education, but it is just not going to happen any time soon.

    What I'm hoping to learn is that instead of "OpenForm" as my macro, there's something else I can run which is equally simple. For the previous question I knew that I was looking for "RunApplication," but this is the option that I can't seem to make work. My last resort is adding a new hyperlink button to the form (which is already loaded with fields).

    Thank you in advance for your time and attention.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,873

    Re: Open PDF from Combo Box in Access

    Here is a possibility that might work for you.

    http://www.datapigtechnologies.com/f...einreport.html

    If this is not something you like then post back. I don't use Macros in Access, but use VBA. I would then suggest some code attached to a command button.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    01-24-2011
    Location
    Minneapolis MN
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Open PDF from Combo Box in Access

    Hi Alan,
    I guess something I neglected to mention is that my target PDF is actually a PDF form including dropdowns and text fields for the end-user to complete, so turning into a picture and plopping into the database is actually re-creating a wheel that doesnt' even need to turn. But I'm glad I got to see that option - might come in handy some day! Well, if these are my best solutions, then I guess it is time to move on to the button option! Thank you so much for looking at my problem.

    Anne

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,873

    Re: Open PDF from Combo Box in Access


  5. #5
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,176

    Re: Open PDF from Combo Box in Access

    I always use this 'module'. Add it to the code, then open ANYTHING (pdf, .doc, .xls) with the command: OpenNativeApp vDoc

    Attribute VB_Name = "modNativeApp"
    Option Compare Database
    Option Explicit

    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Const SW_SHOWNORMAL = 1
    Const SE_ERR_FNF = 2&
    Const SE_ERR_PNF = 3&
    Const SE_ERR_ACCESSDENIED = 5&
    Const SE_ERR_OOM = 8&
    Const SE_ERR_DLLNOTFOUND = 32&
    Const SE_ERR_SHARE = 26&
    Const SE_ERR_ASSOCINCOMPLETE = 27&
    Const SE_ERR_DDETIMEOUT = 28&
    Const SE_ERR_DDEFAIL = 29&
    Const SE_ERR_DDEBUSY = 30&
    Const SE_ERR_NOASSOC = 31&
    Const ERROR_BAD_FORMAT = 11&

    Public Sub OpenNativeApp(ByVal psDocName As String)
    Dim r As Long, msg As String

    r = StartDoc(psDocName)
    If r <= 32 Then
    'There was an error
    Select Case r
    Case SE_ERR_FNF
    msg = "File not found"
    Case SE_ERR_PNF
    msg = "Path not found"
    Case SE_ERR_ACCESSDENIED
    msg = "Access denied"
    Case SE_ERR_OOM
    msg = "Out of memory"
    Case SE_ERR_DLLNOTFOUND
    msg = "DLL not found"
    Case SE_ERR_SHARE
    msg = "A sharing violation occurred"
    Case SE_ERR_ASSOCINCOMPLETE
    msg = "Incomplete or invalid file association"
    Case SE_ERR_DDETIMEOUT
    msg = "DDE Time out"
    Case SE_ERR_DDEFAIL
    msg = "DDE transaction failed"
    Case SE_ERR_DDEBUSY
    msg = "DDE busy"
    Case SE_ERR_NOASSOC
    msg = "No association for file extension"
    Case ERROR_BAD_FORMAT
    msg = "Invalid EXE file or error in EXE image"
    Case Else
    msg = "Unknown error"
    End Select
    ' MsgBox msg
    End If
    End Sub

    Private Function StartDoc(psDocName As String) As Long
    Dim Scr_hDC As Long

    Scr_hDC = GetDesktopWindow()
    StartDoc = ShellExecute(Scr_hDC, "Open", psDocName, "", "C:\", SW_SHOWNORMAL)
    End Function
    Last edited by ranman256; 04-25-2014 at 08:43 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Open MS-ACCESS and Run Saved Imports in Access
    By Manikanta546 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-18-2013, 08:05 AM
  2. Importing Data from Access into my combo box
    By psboyboy13 in forum Access Tables & Databases
    Replies: 1
    Last Post: 11-15-2012, 10:47 AM
  3. Populating combo-box with access db
    By greekboyuk in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-03-2011, 02:18 PM
  4. Combo Box Userform To Open 2nd Combo Box
    By WPJensen in forum Excel General
    Replies: 8
    Last Post: 03-10-2011, 06:33 AM
  5. [SOLVED] Combo Box Values from Access Table?
    By Fattire in forum Excel General
    Replies: 0
    Last Post: 05-24-2005, 02:06 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1