How do I create directory folders based from access database

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to get access to automate creating folders and have them be
named using data from the database?
All suggestions greatly appreciated
 
Hi Craig,

of course... construct your path and then call this procedure:

'~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MakeAPath

Function MakeAPath( _
pPath As String _
) As Boolean

MakeAPath = False

If Len(Dir(pPath, vbDirectory)) > 0 Then
'directory is already there
MakeAPath = True
GoTo Proc_Exit
End If

Dim i As Integer _
, mPos As Integer _
, mStr As String

mPos = 1
If Right(pPath, 1) <> "\" Then pPath = pPath & "\"

mPos = InStr(mPos, pPath, "\")

Do While mPos > 0
mStr = Left(pPath, mPos)
If Len(Dir(pPath, vbDirectory)) = 0 Then
On Error Resume Next
MkDir mStr
End If
mPos = InStr(mPos + 1, pPath, "\")
Loop

If Len(Dir(pPath, vbDirectory)) > 0 Then
MakeAPath = True
GoTo Proc_Exit
End If

MsgBox "Could not make path: " _
& pPath _
, , "Error making " _
& " directory"

Proc_Exit:
Exit Function


End Function
'~~~~~~~~~~~~~~~~~~


Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
Craig B said:
Is it possible to get access to automate creating folders and have them be
named using data from the database?
All suggestions greatly appreciated

You need 2 simple functions, 1 to check if the directory already exists, and
the second to make it if it doesn't:

Public Function DirExists(strDirectory As String) As Boolean
DirExists = (Dir(strDirectory, vbDirectory) <> "")
End Function

Public Function DefaultOutputPath() As String
DefaultOutputPath = "F:\PO\" & Me.lstLots.Column(1) & "\" &
Me.lstLots.Column(2) & "\"
If Not DirExists(DefaultOutputPath) Then MkDir (DefaultOutputPath)
End Function

The function above, makes a folder for Me.lstLots.Column(2) if it doesn't
exist. The structure of the finished folder would look like:

F:\PO\GE\27\

In my case, I know that the PO and GE folders exist, but you could run a
similar function to create them as well.
--
Arvin Meyer, MCP, MVP
Free MS-Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top