We help IT Professionals succeed at work.

MS Access - Save relative path in table and open file on clicking the link

WS
WS asked
on
541 Views
Last Modified: 2018-02-02
Hi,

I have a form that have two field call "Source" and "Destination" taken form tblSou. The source field save the source of document and the destination field save the destination path (which is a server path mapped to local PC's in all the users). Now there are two thing that i want to achieve:

1. Save relative path. (how to save relative path? For example the path is (W:\\Document\test.pdf) how to save it's relative path?)

2. On table when click on that relative link it should open the file. (When the link is click in the table i.e the destination field it doesn't open that document , how to do that?)

Is it possible through VBA by getting the root directory of the folder and appending the filename?

Any help would be appreciated.

Thank you.
Comment
Watch Question

Máté FarkasSQL Server Consultant
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
WSStudent

Author

Commented:
@Mate, thanks for explaning so well, i was a bit confuse but now it's more clear to me. I have 2 question here :

1. In (Replace(FullPath, StaticPath,) , how FullPath and StaticPath will be declared? I have static folder as W:\Document\ and after this there are 10 folder's where user will save the file in anyone of them.

2.I have a server in which Document Library is build which is mapped to my PC. In this scripting runtime "("C:\MyApp\Documents\Important\FirstDocument.docx")" , i will replace it as W:\Document\ , here for FirstDocument.docx it should get the destination path which will be like test.pdf or whatever is there, how that can be done?

Thank you again.
WSStudent

Author

Commented:
In the fields Source and Destination i have code , in Source it open folders and user select document and then in Destination user select the destination location where user copy the file. How can i incorporate the above code in this? any idea?
Private Sub txtSource_Click()
 Dim Dialog      As FileDialog
    
    Dim Selected    As Long
    
    Set Dialog = FileDialog(msoFileDialogFilePicker)
    With Dialog
        .AllowMultiSelect = False
        .InitialFileName = Nz(Me!txtSource.Value)
        .Title = "Select file to copy"
        Selected = .Show
        If Selected <> 0 Then
            Me!txtSource.Value = .SelectedItems.Item(1)
        End If
    End With
    
    Cancel = True
End Sub

Private Sub txtTarget_Click()
Dim Dialog      As FileDialog
    
    Dim Selected    As Long
    
    Set Dialog = FileDialog(msoFileDialogSaveAs)
    With Dialog
        .AllowMultiSelect = False
        .InitialFileName = Nz(Me!txtTarget.Value)
        .Title = "Name saved file"
        Selected = .Show
        If Selected <> 0 Then
            Me!txtTarget.Value = .SelectedItems.Item(1)
            If Not IsNull(Me!txtSource.Value) Then
                 FileCopy Me!txtSource.Value, Me!txtTarget.Value
            End If
        End If
    End With
    
    Cancel = True
End Sub

Open in new window

CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
WSStudent

Author

Commented:
Thank you PatHartman.
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
You're welcome