Max Wanadoo
max.wanadoo at gmail.com
Thu Mar 18 04:57:16 CDT 2010
Gustav,
Ah yes, you are correct BUT I have started to set up a little CLASS to
handle these and will have the same functionality. After all .net is just a
collection of these little classes.
I thank you....Max
Here is the test:
Sub test1()
Dim cls As New clsFolders
Dim spath As String
spath = cls.libCurrentFolder(CurrentProject.Path) & "MyPic.jpg"
Debug.Print spath
Debug.Print CurDir, CurrentProject.Path
Call cls.libSetCurPathToProjectPath
Debug.Print CurDir, CurrentProject.Path
Call cls.libResetCurPathFromProjectPath
Debug.Print CurDir, CurrentProject.Path
End Sub
And here is the CLASS:
Option Compare Database
Option Explicit
Public libStrProjPath As String, libStrProjDrive As String, libStrCurPath As
String, libStrCurDrive As String
Public Function libCurrentFolder(strIn As String) As String
' this function ensures that there is a trailing backslash (\) at then end
of a path.
' useful when appending a file name to, say currentproject.path
' example of use: MyFile = clsFolder.libCurrentFolder(CurrentProject.Path) &
"MyPic.jpg"
Dim strL As String, strR As String
strL = Left(strIn, 2)
strR = Replace(Mid(strIn, 3) & "\", "\\", "\")
libCurrentFolder = strL & strR
End Function
Public Sub libSetCurPathToProjectPath()
' Declare the varibles as public so that they can be retained for
re-setting back.
' this is used when there is a need to Shell out to a (say) a batch file
located in the same
' folder as the application but you don't want to have to put the full
path in for the
' system application which will be invoked by the (say) batch file and
prefer to let the
' OS itself locate the object. If you do not set the path before hand then
typically you will
' have the Current Drive DIFFERENT to the Project Path Drive.
' This will line them up. It is used in conjunction with
libResetCurPathFromProjectPath
' get the project location:
libStrProjPath = CurrentProject.Path: libStrProjDrive =
Left(libStrProjPath, 1)
' get the current location
libStrCurPath = CurDir: libStrCurDrive = Left(libStrCurPath, 1)
' change the current location to the project location so that we can run
the blat.exe via the batch.bat file etc
ChDrive libStrProjDrive: ChDir libStrProjPath
End Sub
Public Sub libResetCurPathFromProjectPath()
' this is the counterpart to libSetCurPathToProjectPath()
' now restore the current location back to what it was.
ChDrive libStrCurDrive
ChDir libStrCurPath
End Sub
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gustav Brock
Sent: Thursday, March 18, 2010 9:10 AM
To: accessd at databaseadvisors.com
Subject: Re: [AccessD] CurrentProject.Path syntax?
Hi Max
This thread demonstrates yet another reason to turn to something more
clever.
In Visual Studio (dotNet) this is done in one line which tells it all:
someFile = Path.Combine(somePath, someFileName);
freeing your valuable time from low-level stuff like if a backslash is
present or not.
/gustav
>>> max.wanadoo at gmail.com 17-03-2010 22:45 >>>
Bit more complicated.
str = "\\svr\c\"
strL = Left(str, 2)
strR = Replace(Mid(str, 3) & "\", "\\", "\")
str = strL & strR
Max
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com