creating a folder

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

Guest

Hi all!
I am having a brain melt. Is there a way in Access2k to have vb create a
file folder on a hard drive? What I am trying to do is when an order is
generated in Access a folder is created using the order number and a copy of
the Access generated order is placed in the folder. I can move the order with
no problem to an established folder, but I need to be able to create a folder
on the fly. Thanks in advance for any assistance, If I have placed this post
in the wrong area please let me know and I will repost in the proper area.
jmillerwv
 
Hi,
Thanks for the quick response. I thank you for the suggestion but I have one
other question How is it used? Wiht the docmd action or as just a statement
is VB? Only way I could get it to work was using the command promt. Again
thank you for your assistance.
jmillerwv
 
Hi.
How is it used?

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.
 
Hi.
Again thank you for your assistance na dquick response. I will try as per
your example and I apologize for posting in the wrong area. Again thank you
for your assistance and God bless.

jmillerwv
 
You're very welcome.
and I apologize for posting in the wrong area.

No problem. There aren't any sign posts to tell you that beginners get the
best service in the new users newsgroup
(microsoft.public.access.gettingstarted), experts get the best service in
the programming and queries newsgroups
(microsoft.public.access.modulesdaovba and microsoft.public.access.queries),
and intermediate through advanced users get the best service in the other
Access newsgroups. And the regulars complained about the sign posts telling
questioners how to get the fastest free service in these newsgroups, so you
won't even find those anymore.

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.
 

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