open a pad from access form

steve2

Registered User.
Local time
Yesterday, 21:59
Joined
Nov 24, 2017
Messages
22
I tought this would be easy, but I'm bumping on a wall:

I can now open a specific file on my computer, based on fields firstname and lastname (thanks to the forum's help) .

Now I'm trying to open the map (which holds all client's related files, so in my case the one that stands above the .txt file). It doesn't work, nor with Shell, nor with Followhyperlink.

-------------
Here are the two codes I tried:

1) Shell explorer.exe:

Private Sub Command282_Click()
On Error GoTo Err_Knop282_Click

Dim Foldername As String
Dim stnaamfile As String
stnaamfile = Me.ACHTERNAAM & "" & Me.VOORNAAM
Dim LResult As String
LResult = LCase("stnaamfile")
Foldername = "\\server\c:\Users\eigenaar\Documents" & stnaamfile & "\"


Shell "C:\WINDOWS\explorer.exe """ & Foldername & "", vbNormalFocus


Exit_Knop282_Click:
Exit Sub

Err_Knop282_Click:
MsgBox Err.Description
Resume Exit_Knop282_Click

End Sub

____________________

2) the one with Followhyperlink

Private Sub Command282_Click()
On Error GoTo Err_Knop282_Click

Dim Foldername As String
Dim stnaamfile As String
stnaamfile = Me.ACHTERNAAM & "" & Me.VOORNAAM
Dim LResult As String
LResult = LCase("stnaamfile")
Foldername = "\\server\c:\Users\eigenaar\Document" & stnaamfile

Application.FollowHyperlink Foldername



Exit_Knop282_Click:
Exit Sub

Err_Knop282_Click:
MsgBox Err.Description
Resume Exit_Knop282_Click

End Sub

------------------------------------
All I'm opening is the 'Document' file (which stands for 'my documents').
It doesn't go any further, no matter what I change.
I cannot get vba to comprehend the 'stnaamfile' .

Can anyone give me a suggestion of what I'm doing wrong?
 
For starters, you'd need a backslash between Documents and the file name.
 
And to reinforce that point, add Debug.Print line(s) to check the path given in your code is what it should be
 
1) would also require a space to be inserted before Foldername. Colin's suggestion will point that out.
 
Thank you for the suggestions, but I tried it with the \ after 'documents', but it still doesn't find the path.
It's the line:
Foldername = "\\server\c:\users\eigenaar\Documents" & stnaamfile & "" that doesn't work. (it only opens the 'documents' folder)
So my expression " & stnaamfile & seems to be missing something

(I admit that my knowledge of vba is veryvery basic)
 
Did you add the debug.print line as suggested?
 
sorry Colin, I know it's good advice, but I'm not familiar with it, looked a bit on the internet to know where to put the code -before or after... (would be great if you give me the example in a code where I have to put it).

In the mean time, I think I found the solution (it works)

---------------
Private Sub Command282_Click()
On Error GoTo Err_Knop282_Click

Dim Foldername As String
Dim stnaamfile As String
stnaamfile = Me.ACHTERNAAM & "" & Me.VOORNAAM
Dim LResult As String
LResult = LCase("stnaamfile")
If Nz(stnaamfile, "") = "" Then
Foldername = "c:\Users\eigenaar\Documents"
Else
Foldername = "c:\Users\eigenaar\Documents" & stnaamfile
End If
Shell "C:\Windows\explorer.exe """ & Foldername & "", vbNormalFocus


Exit_Knop282_Click:
Exit Sub

Err_Knop282_Click:
MsgBox Err.Description
Resume Exit_Knop282_Click

End Sub

-------------------------
I copied some code from a french site. (I watch and I learn, but very slowly and I admit, sometimes without understanding )
Thought it would also create a new foldername if not existed, but that part seems not to be working. So let's say that I'm partially happy...
 

Users who are viewing this thread

Back
Top Bottom