hi Friends!
i need to open a pdf documents from MsAccess.
Please send me the code.
Then i need to create a BROWSE button such that

BROWSE_BUTTON Text_box

When i click the browse button it should work as ordinary windows browse button and when i select some files, the "File-Path" has to be stored in the text_box.

I need the code urgently. Plz send me.
Thanks in advance
Elanch

Dani AI

Generated

Following 's description (a table field holding the PDF path bound to a textbox), and answering 's request for code, here are compact, ready-to-use examples for two buttons: a Browse button that writes the selected file path into the textbox, and an Open button that launches the PDF. Replace control names (txtFilePath, cmdBrowse, cmdOpen) with the actual names on the form (for example the bound Path_file textbox).

' Browse button (Access 2007+)
Private Sub cmdBrowse_Click()
    Dim fd As FileDialog
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    With fd
        .Title = "Select a PDF file"
        .Filters.Clear
        .Filters.Add "PDF Files", "*.pdf"
        .AllowMultiSelect = False
        If .Show = -1 Then Me.txtFilePath = .SelectedItems(1)
    End With
    Set fd = Nothing
End Sub
' Open button (robust, checks file exists)
Private Sub cmdOpen_Click()
    Dim sPath As String
    sPath = Nz(Me.txtFilePath, "")
    If sPath = "" Then
        MsgBox "No file specified.", vbExclamation: Exit Sub
    End If
    If Dir(sPath) = "" Then
        MsgBox "File not found: " & sPath, vbExclamation: Exit Sub
    End If
    On Error GoTo ErrHandler
    Application.FollowHyperlink sPath
    Exit Sub
ErrHandler:
    MsgBox "Unable to open file: " & Err.Description, vbCritical
End Sub

For greater compatibility (and for 64-bit Office), use ShellExecute. Add the conditional Declare and call it if FollowHyperlink fails.

Troubleshooting and notes:

  • Stored path must include filename and extension; convert relative paths with CurrentProject.Path & "\" & storedName if needed.
  • If Application.FileDialog is unavailable, add a reference to the Microsoft Office Object Library or use an API fallback.
  • If PDFs won’t open, check that a PDF viewer is installed and that the path is accessible (network permissions, UNC vs mapped drives).
  • Keep paths consistent (prefer UNC for network shares) and validate paths with Dir before attempting to open.

This directly answers the request in the thread and provides small, practical procedures that can be dropped into the form's module.

Recommended Answers

All 3 Replies

Experts are here to help you but not do your home work. To get any help you need to post how / what y have done to solve your problem with code.

and again your questions is a bit confusing.
can u please clarify what do ypu mean by i need to open a pdf documents from MsAccess.

i am not sure what you want to do
1. you are using access forms .
or
2. filenames are stored in acces table.

Please post your question clearly.

hello sir!

Sorry for the unclear question. let me brief it again.
I have created a field name Path_file in a table.
The path for different pdf files are stored record wise. And i have created a form to open the pdf file stored in the path
Eg:

Pathfile_text box

open_button

When i click the open button, it has to open the file stored in the textbox.
Thanking you
elanch

Elanch,

Please contact me through the thread. I am finding difficulty to read your private mail. It eats up my time.

Are you all positive to my enquiry?

Please answer me.

Regards
AV Manoharan

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.