Hi.
For future reference, post questions in the newsgroup for new users, since
the answers there are geared for beginners, and the responders don't assume
you will understand the directions given:
http://www.microsoft.com/office/com...ft.public.access.gettingstarted&lang=en&cr=US
If you post questions in the other Access newsgroups, like this one, it's
assumed that you are not a beginner (otherwise, you would have posted in the
new users newsgroup), so the answers given expect you to have at least some
experience with Access. However, we're happy to provide step-by-step
instructions to clarify any concepts you don't understand, but those
step-by-step instructions won't be offered on the first post like they would
be for beginners in the new users newsgroup, because experienced users don't
need the extra help.
The suggested code should be saved inside a VBA procedure in your database
application. Press <ALT><F11> to open the VB Editor. Select the Insert ->
Module menu to create a new module. Paste the following code into this new
module:
Public Function createNewDir(sPath As String, sNewDir As String) As Boolean
On Error GoTo ErrHandler
MkDir sPath & "\" & sNewDir
createNewDir = True
Exit Function
ErrHandler:
MsgBox "Error in createNewDir( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear
createNewDir = False
End Function
Save and compile the code. Name the new module anything other than an
object already in the database application and other than the name of a
procedure in any code module. Now, since it's a public function, it can be
called from VBA code, a macro, or a property elsewhere. As an example, the
following procedure could be used:
Public Sub testNewDir()
On Error GoTo ErrHandler
Dim sOrderNum As String
Dim fSuccess As Boolean
sOrderNum = "123" ' Use whatever function you have to generate the
order #.
fSuccess = createNewDir(CurrentProject.Path, sOrderNum)
MsgBox "Directory created successfully = " & fSuccess
Exit Sub
ErrHandler:
MsgBox "Error in testNewDir( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear
End Sub
.. . . where CurrentProject.Path is the current directory where your database
application is located. This could be replaced with another directory path
by using either a string variable or a hard-coded string, such as
"C:\Work\MyDir" like the following:
fSuccess = createNewDir("C:\Work\MyDir", sOrderNum)
.. . . which would create the C:\Work\MyDir\123 directory.
HTH.
Gunny
See
http://www.QBuilt.com for all your database needs.
See
http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.