Attaching file to a database

I want to attached a file(pdf) to a database in a way that I dont have to write path name when I search of this file. Is it possible?
AiyshaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

josephwalshCommented:
You could try using the microsoft common dialog control on the form. (MSCOMCT2.OCX)
Private Sub cmdBrowse_Click()
On Error GoTo Err_cmdBrowse_Click

    CommonDialog.Filter = "Import Files ( *.imp )"
    CommonDialog.ShowOpen
    txtFileName = CommonDialog.FileName

Exit_cmdBrowse_Click:
    Exit Sub

Err_cmdBrowse_Click:
    MsgBox Err.Description
    Resume Exit_cmdBrowse_Click
   
End Sub

Create a text box control 'txtFileName' to hold the name of the file.
Create a Browse command buttton named 'cmdBrowse'.
Use the code below on the click event.

Private Sub cmdBrowse_Click()
On Error GoTo Err_cmdBrowse_Click

    CommonDialog.Filter = "Import Files ( *.imp )"
    CommonDialog.ShowOpen
   with me
    !txtFileName = CommonDialog.FileName
  end with

Exit_cmdBrowse_Click:
    Exit Sub

Err_cmdBrowse_Click:
    MsgBox Err.Description
    Resume Exit_cmdBrowse_Click
   
End Sub
0
harfangCommented:
I'm not sure what you need.

You could for example create a label with "open PDF", and then insert the full path and name into the label's Hyperlink address.

Or explain what you mean by "attach a file"...

Cheers!
(°v°)
0
AiyshaAuthor Commented:
"attach a file" meand I dont want to specify the path..I think the import , your first answer is what I need.. I will try it and let you know.
0
harfangCommented:
> I dont want to specify the path

I'm guessing that you want to "attach" a document to a record in a table. Typically, you would store only the file name, or a *relative* path. If you store absolute paths, e.g. "U:\Common\Docs\Cool.pdf", you will make have a very complex maintenance problem.

The typical solution is to store a fixed "file root" path, in which all the "attached" files must be stored. That way, you can more easily maintain the data integrity.

The solution provided by josephwalsh basically allows you to browse for a file instead of typing in the file name. However, this does not address the problem of the storage and maintenance of a list of "attached" files.

I'm not sure this helps, feel free to correct me.
(°v°)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.