• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 370
  • Last Modified:

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?
0
Aiysha
Asked:
Aiysha
  • 2
1 Solution
 
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now