get round limit in the path length

D.Mair

David
Local time
Today, 12:44
Joined
Jun 1, 2001
Messages
33
Hi

Well my problem is I have created a button to export data to word then save the information in a specific file for each separate job. This works fine if I use a short path name but the files that these documents are in have long paths ie:

\\sac039\global$\Building Design\Projects\2002 Projects\2002400 test\Correspondence\2002400-AA

The code I used is

ObjWord.ActiveDocument.SaveAs (Trim(txtFolder) & Trim(txtReportResult))
ObjWord.Quit

Is there anyway to get round the limit in the path length??

Thanks in anticipation.
David.
 
How about parsing each path segment like Windows does for Win 95 compatibility? That is: Limit each segment to 8 characters. Those over 8: replace the 7th and 8th characters with "~1"
 
That might work but I am not sure of how to get the code to work!
this is the code

Place this code in a .bas module

Option Explicit

Public Declare Function GetShortPathName Lib "kernel32" _
Alias "GetShortPathNameA" _
(ByVal lpszLongPath As String, _
ByVal lpszShortPath As String, _
ByVal cchBuffer As Long) As Long

Public Function GetShortName(sFile As String) As String
Dim sShortFile As String * 67
Dim lResult As Long

'Make a call to the GetShortPathName API
lResult = GetShortPathName(sFile, sShortFile, _
Len(sShortFile))

'Trim out unused characters from the string.
GetShortName = Left$(sShortFile, lResult)

End Function

Now place this code in the Form_Load event

Private Sub Form_Enter()

Debug.Print GetShortName(App.Path)

End Sub

I have created the module
And put the code on the form on the enter event But i don't know what to put in the (App.Path) part.

thanks for any help

David
 
App.Path is a parameter passed to the function GetShortName. You can pass it either a string or a literal.
 
I can't get it to work.

Could you tell me what bits I need to change to = whatever.

I am Glad it is Friday it's been a long week.

Thanks for your time!

David
 
David,

Without more info I'm not sure how to help you. But here are some random, miscellaneous thoughts.

- Make sure you don't have Option Explicit duplicated in your Module

- Debug.Print will print the short path name in the Immediate Window or Pane, so look for it there

- I notice you have a Private Sub named Form_Enter rather than Form_Load, and I'm not sure why

- Change "Debug.Print GetShortName(App.Path)" to "MsgBox GetShortName(CurrentDb.Name)" -- and don't include the double quote marks, only that which is between them
 
Well to clarify what I am trying to do is
Get a long path name (in a text box which is different on each record of a form) that has to be converted into a short path and placed in another text box on the same record on the same form.
This means that I can export data to word then save the information in a specific file for each separate job.
 
You mean like this?

Private Sub Form_Load()
Me!txtLongPath.SetFocus
Me!txtLongPath.Text = CurrentDb.Name
End Sub

Private Sub txtLongPath_Change()
Dim strPath As String
strPath = GetShortName(Me!txtLongPath.Text)
Me!txtShortPath.SetFocus
Me!txtShortPath.Text = strPath
End Sub
 

Users who are viewing this thread

Back
Top Bottom