Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if pathname exist 1

Status
Not open for further replies.

checkOut

Technical User
Oct 17, 2002
153
NL
I have next function to implement

Public Function SetSaveName(lngLead As Long) As String
Dim lngDeb As Long, strProject As String, stLink As String
Dim strPath As String
stLink = "[MP_id] = " & lngLead
lngDeb = Nz(DLookup("debiteurnr", "MARKTPARTIJ", stLink), 0)
strProject = Nz(DLookup("bedrijfsnaam", "MARKTPARTIJ", stLink), "")
strPath = "C\" & lngDeb & "\" & strProject

End Function

Now I want to check If path already exist.
If it exists it's oke and I go further to set
SetSaveName to strPath & "blabla.doc"
IF it not exists I have to create the path.
Anyone an idea to handle this?
I have no idea to check the path and I have no idea to create the path. So any help very appreciated,

Gerard
 
Gerard,

Something like this would do it:

Code:
p_sSearchName = &quot;<DirectoryName>&quot;
If Dir(p_sSearchName, vbDirectory) = &quot;&quot; Then ...

HTH

Cheers
Nikki :)
 
Thanx nikki, that's right, but now I need something to create if it doesn't exist, any idea?

Public Function SetSaveName(lngLead As Long) As String
Dim lngDeb As Long, strProject As String, stLink As String
Dim strPath As String, Init As String, strFile As String
strFile = &quot;geen offerte.doc&quot;
Init = &quot;C:\&quot;
stLink = &quot;[MP_id] = &quot; & lngLead
lngDeb = Nz(DLookup(&quot;debiteurnr&quot;, &quot;MARKTPARTIJ&quot;, stLink), 0)
If FileExists(Init & lngDeb) Then
strProject = Nz(DLookup(&quot;bedrijfsnaam&quot;, &quot;MARKTPARTIJ&quot;, stLink), &quot;&quot;)
If FileExists(&quot;C:\&quot; & lngDeb & &quot;\&quot; & strProject) Then

else
'code to create dir strProject in Init/lngDeb (&quot;C:\203\&quot;)
End If
Else
'code to create dir lngDeb in Init (&quot;C:\lngDeb&quot;)
End If
Debug.Print strPath
End Function

Function FileExists(fname As String) As Boolean
If Dir(fname, vbDirectory) <> &quot;&quot; Then _
FileExists = True _
Else FileExists = False
End Function
 
Hiya,

Use MkDir &quot;<PathName&quot;> in VBA to create the Directory (it's in the VBA help file, btw)

A fuller list;
VBA Function Description
Dir Returns the name of a file, directory, or folder that matches a specified pattern or file attribute.
GetAttr Returns the attributes of a file, directory, or folder.
SetAttr Specifies the attributes of a file, directory, or folder.
CurDir Returns the current directory.
ChDir Changes the current directory.
ChDrive Changes the current drive.
MkDir Creates a new directory.
RmDir Removes an existing directory.
Kill Deletes one or more files.
FileLen Returns the length of a file on disk in bytes.
LOF Returns the length of an open file in bytes.
FileCopy Copies a file on disk.
FileDateTime Returns the date and time a file was created or last modified.
Name Renames a file and moves it to another location on disk.
Open Opens a file on disk for reading or writing.
Input Reads characters from an opened file.
Print Writes text to a sequential file.
Write Writes text to a sequential file.
Close Closes a file that was opened using the Open statement.


HTH

Cheers
Nikki
 
Thanx a lot, Nikki
I'll CHECK this OUT ;)

Greetz,

Gerard
 
Following the line above I need a function to rename a directory.
I save all ProjectNames like
G:\DocumentsCRM\ProjectName\(4 submaps)

It's possible to change the ProjectName, so in the AfterUpdate of this field I call the function

ChangeDirectory(me.projectname.oldvalue, me.projectname.value)

Sub ChangeDirectory(strOldName as string, strNewName as string)
But How Can I change the Directory from
G:\DocumentsCRM\ProjectName\(4 submaps) (old) to
G:\DocumentsCRM\ProjectName\(4 submaps) (new)?


Thnx in advance,

Gerard
 
Gerard,

is dit wat je nodig hebt? Dit hernoemt een bestand of map in VBA (syntax zoals geschreven!)

Code:
Name <DirectoryName> As <Directoryname>

HTH

Cheers
Nikki (Amsterdam-based)
 
Nikki,
you're great,

Altijd leuk mensen te ontmoeten die op een bepaald vlak meer weten, scheelt een hoop tijd...
Als ze nog 'dutch-speaking' zijn... dat ben ik helemaal niet gewent op 't WEB.

Greetz,
Gerard
 
Hey, ANY time I need some Access help - dan weet ik je wel te vinden ;-)

and you're welcome

Cheers
Nikki
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top