getting access to create folders using field data

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

Guest

I need to get access to create a folder on my computer using data such as the
job name in a field in the database. I want it to do this by clicking a
button on a form and it popping with the newly created folder and therfore
then being able to drag fiels into that folder which relate to that job,
thanks for any help, WK
 
This type of thing would require several components. First of all, you cannot
drag elements from inside Access to a Windows folder without significant API
calls. Dev Ashish has a sample of dragging from Explorer into Access
(http://mvps.org/access/api/api0032.htm), but not the other way. I would
suggest using a Treeview control to expose the folders and files you are
working with.

To create a folder and do many other folder/file operations, you could use
the FileSystemObject's methods.

Finally, Access doesn't have native drag and drop events, like you have in
VB6 or .Net. There are a few workarounds, though, like in this article:
http://support.microsoft.com/?kbid=287642 or available as add-ins, like here:
http://www.peterssoftware.com/dd.htm

Needless to say, if you're new to VBA, this wouldn't be a good project to
take on; it will take a fair amount of very creative code.

Barry
 
Hi there, thanks for your prompt reply, i think i may have been a tiny bit
unclear on part of it, firstly yes i am relatively new to access! What i want
to do in acceess is by clicking a button it uses a field entry such as the
job name eg 'hotelympia' and use this to create a folder on the c:\data\
folder, eg. c:\data\hotelympia\ and then get this window to pop up, so that
if i were to scan in an invoice i can attach that scanned file by scanning or
purely saving in the scan program into the folder i have created with a link
directly to it from the record in access, i hope that may make more sense,
the simpler the way of doing it the better, or in fact if there is a better
way of doing it! thanks again, WK
 
Here's the simplest version of this I can think of. Put this code into a
command button's OnClick event:

Dim fsoThis As New FileSystemObject
Dim strPath As String
strPath = "C:\Data\" & Me.MyFieldlValue
If Not fsoThis.FolderExists(strPath) Then 'Check to see if it already
exists.
fsoThis.CreateFolder (strPath) ' Create the folder.
End IF
Shell "explorer.exe " & strPath, vbNormalFocus ' Open Explorer to that
folder.
Set fsoThis = Nothing

Replace MyFieldValue with the name of a control or field that contains the
path you want to build.

Barry
 
I equate "simpler" with "don't require any additional references", so I
consider this simpler:

Dim strPath As String

strPath = "C:\Data\" & Me.MyFieldlValue
If Len(Dir(strPath, vbDirectory)) = 0 Then
MkDir strPath
End If
Shell "explorer.exe " & strPath, vbNormalFocus
 
Back
Top