Results 1 to 7 of 7
  1. #1
    hstroud38 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2012
    Posts
    3

    Exclamation mkdir basic help - create folder for each new record

    Hi,



    I want to create a folder for each new record in my access database. I understand that you need to use a mkdir statement, but I do not know where or how to do this. I can open VBA editor, but from there I am stuck.

    Can someone please provide me with some basic instructions that can be understood by the laymen?

    Thanks,

  2. #2
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    I don't know how you would do so but I'm extremely interesting in finding out why in the world you would want to do so.

  3. #3
    hstroud38 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2012
    Posts
    3
    Quote Originally Posted by TheShabz View Post
    I don't know how you would do so but I'm extremely interesting in finding out why in the world you would want to do so.

    I need to create a directory for each record, in my case a distinct work order, where I can store photographs and invoices that are related with them. I do not wish to store these in the database itself in order to keep down size.

    Does that answer your question?

    This seems like a common question on forums, yet I haven't been able to find an explanation on how to do it that someone with limited knowledge of VBA can follow.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    I found this in some old code
    Code:
    '---------------------------------------------------------------------------------------
    ' Procedure : MakeDir
    ' DateTime  : 2005-06-28 10:20
    ' Author    :  
    ' Purpose   : To make a Directory from within VBA. It checks if
    '             the Directory to be created already exists, and gives
    '             an Error message if so.
    '
    'Parameters:
    'sDrive  - the Drive on which the new directory is to be built
    'sDir    - the new directoryName
    '
    'Note:   - Only creates 1 level per call
    '        - the sDir must have leading \ for each level of directory
    ' eg  MakeDir "C" ,"\level1"         <--call 1
    '     MakeDir "C" ,"\level1\level2"  <--call 2
    '     will create c:\level1\level2  <--2 Calls required
    '---------------------------------------------------------------------------------------
    '
    Sub MakeDir(sDrive As String, sDir As String)
    
    On Error GoTo ErrorFound
    VBA.FileSystem.MkDir sDrive & ":" & sDir
    goto Exxit
    ErrorFound:
    If Err.Number = 75 Then
     MsgBox "Err 75 - Directory (" & sDrive & ":" & sDir & ") already exists"
    Else
    MsgBox Err.Number & " other error " & Err.Description
    End If
    Exxit:
    End Sub

  5. #5
    hstroud38 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2012
    Posts
    3
    Hi Orange,

    Thank you for the help. Unfortunately, I do not know where to place the code, or how to make it automatically run each time a new record is created. Essentially what I am looking for is this: I want to know how to make a VBA MkDir statement that will generate a folder each time a new record is created in the database and use a value from a field to name the folder. That is all.


    Thanks again!

  6. #6
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    You ask that it be put so a lay person can understand it, sometimes a 'simple' task is not quite so simple, and vba is a necessity for all the odd or unusual things you might want to do (and also a lot of the common things you will want to do).

    In this case, you want to create a new directory, in an unspecified location, for each new record in a table (database refers to the entire file essentially and therefore across multiple tables).

    Oranges code will perform the required function. (It will need to be added to a visual basic module)

    You need to place the code on a form, in the after insert event.
    the line would read something like (as shown in oranges code in the comments):

    MakeDir "C" ,"\level1"

  7. #7
    manic is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    63
    if you are saving the records as a PDF or any other file I use the following:

    Private Sub CmdSavetoFile_Click()
    On Error GoTo Err_LogErrors
    Me.Refresh

    Dim stDocName As String
    Dim strPath As String

    strPath = "L:\Operations\managers\" & DatePart("yyyy", Date_of_Log) & " Operator Log\ " & Me.Department & "-" & Me.Shift & "-" & "Shift"
    If Dir(strPath, vbDirectory) = "" Then MkDir (strPath)

    stDocName = "Report Operator Log"
    DoCmd.OutputTo acReport, stDocName, acFormatPDF, strPath & "\" & Employee_Name & "_" & Format(Date_of_Log, "yyyymmdd") & ".pdf"


    Exit_CmdSavetoFile:
    Exit Sub
    Err_LogErrors:
    Call LogErrors(err.Number, err.Description, "CmdSavetoFile Failed,Operator Log Form")


    Resume Exit_CmdSavetoFile

    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. PLEASE HELP Send Report to MkDir Path
    By alyon in forum Access
    Replies: 17
    Last Post: 12-06-2011, 05:56 PM
  2. VBA to create PDF and folder if doesn't exist!
    By crxftw in forum Programming
    Replies: 2
    Last Post: 08-08-2011, 08:53 AM
  3. Check path in another form and create folder
    By anandram in forum Programming
    Replies: 6
    Last Post: 05-02-2011, 12:23 PM
  4. create On Click to go to specific server folder
    By airhud86 in forum Programming
    Replies: 1
    Last Post: 01-05-2010, 12:45 PM
  5. Replies: 0
    Last Post: 12-16-2009, 09:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums