Link to home
Start Free TrialLog in
Avatar of HOTWATT
HOTWATTFlag for United States of America

asked on

Adding attachments into Access database

Is there an easy way to allow users to add attachments into an access database? I am thinking having the documents shared on a server and some how linking them into the data base so they can be pulled up easily. Is there an easy way for users to add attachments/attachment links easily?
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Create a textbox and set its property IsLink to True.

Now, type in the path to the file.
When clicked, the document will open.

/gustav
Avatar of HOTWATT

ASKER

Is there a way to have a dialog box where the person can pick where the document is located? I am just trying to think of a way to make it as simple as I can for the users. I feel like them having to type the path would not go over well.
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HOTWATT

ASKER

So I created a button that brings up a dialog box. You pick the file you want and that populates a separate txt box with the path. That text box is set to be a hyperlink. But when I click on the path that is in the txt box it does not bring anything up. Any idea why?  I uploaded a photo of the txt box with the path. If you need the code I can send that.
attachments.PNG
No code is needed to open the document. Just click the textbox.

/gustav
If you don't want to use the FollowHyperlink method which requires a minimum of a single line of code if you are willing to dispense with error trapping, then you must define the field at the table level as a hyperlink.  This is an Access-specific data type and will not upsize if SQL Server is in your future so you would need to convert the data and add code similar to what I posted at that time.
Avatar of HOTWATT

ASKER

So I figured out the reason the links are not opening is because when I choose the file from the dialog box the path that gets entered into the txtpath field starts with a C:\ instead of C:\\. Once I add the second \ it will open correctly. Any idea how to get the path to automatically add the second \ when the file is chosen from the dialog box picker?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HOTWATT

ASKER

Where exactly would you add that into the code? Also would that just change the first \ or would that change all of them in the path?

Private Sub attachment_Click()
Dim dialog As FileDialog
Set dialog = Application.FileDialog(msoFileDialogFilePicker)
With dialog
.AllowMultiSelect = False
.Show
Me.txtpath = .SelectedItems.Item(1)

End With

End Sub
Here:

    Me!txtPath.Value = Replace(.SelectedItems.Item(1), "\", "\\")

/gustav
Avatar of HOTWATT

ASKER

Thing is that replaces every \ with a double \. I just need the first \ of the path to be double \
Then replace that:

    Me!txtPath.Value = Replace(.SelectedItems.Item(1), ".\", ".\\")

/gustav
Avatar of HOTWATT

ASKER

hmm that one didn't seem to work. Beginning still has one backslash.
Oh, it should have been:

    Me!txtPath.Value = Replace(.SelectedItems.Item(1), ":\", ":\\")

/gustav
Avatar of HOTWATT

ASKER

Thanks I ended up figuring that part out forgot to post it here. For some reason I am still having an issue where the link wont open unless I type in the txt box first and hit enter. For example If I select a file  and try and click it wont open but as soon as I click into the txt box and put a space at the end or erase a letter and put it back in then hit enter it becomes a clickable hyper link.
That's because the octothorpe wrapping is missing:

Private Sub attachment_Click()

    Dim Dialog As FileDialog

    Set Dialog = Application.FileDialog(msoFileDialogFilePicker)
    With Dialog
        .AllowMultiSelect = False
        .Show
        If .SelectedItems.Count = 1 Then
            Me!txtpath.Value = "#" & .SelectedItems.Item(1)  & "#"
        End If
    End With

End Sub

Open in new window

/gustav
Avatar of HOTWATT

ASKER

That was the issue! Thanks so much for the help! I really appreciate it.
You are welcome!

/gustav