Create a network folder with the user's name

Rx_

Nothing In Moderation
Local time
Today, 08:04
Joined
Oct 22, 2009
Messages
2,803
My MS Access application provides all reports using Excel Automation.
When a user selects a report, the Excel report is saved on a network drive in a folder X:\MyBusiness\MyUserCommunity\Database Reports\UserID\ReportName\<date/time>ReportName<filterlist>.xls

The first step for a new user for the database is to create a folder named with the user id. This subroutine is called from the report form's open event. If it already exist, do nothing - else create it.

The advantages of each user having a folder, then a subfolder named for each report type plus the date time stamp in the report name: It provides an automated filing system for each user.
For Citrix Users - this provides a simplistic way to save reports running on a common server.

Code:
Sub FirstTimeUser()
          ' If a new user is added to the DB - opening the reports form checks to see if the user directory exist
          ' The rest of the reports will add a sub directory to this one.
          ' A user might delete their folder, this will check and see that the folder is missing, and create a new one
            Dim strNewReportPath        As String  ' for directory to save
            Dim UserLogin               As String
            Dim UserPath                As String
            Dim msgString               As String
            Dim DirName                 As String
            Dim Response                As String
10    On Error Resume Next
20    UserLogin = Environ("username")
30    UserPath = "X:\MyBusiness\MyUserCommunity\Database Reports\" & UserLogin
40    strNewReportPath = UserPath
50    DirName = strNewReportPath
60        If Dir(DirName, vbDirectory) = "" Then
70                  DirName = UserPath
80                  MkDir DirName
90                  Err.Clear ' 
100         Else
110                 Exit Sub
120         End If
130   Exit Sub
End Sub
 
I use something similar whereby I have user id then I use the file type as a directory and within each directory I name files by the year then a middle fix then an incremental ending before a description. So my first excel file of 2013 will be located as follows

userid\xls\2013xls001FirstExcelfile.xls

I like it because apart from the descriptive text its completely objective.
 
Last edited:
Exactly on the mark! I so much the same, it helps the staff organize the reports (reports created in Excel).

Adding the YYYYMMDD to the front of the name goes a long way to organize the user's folders.

Would always appreciate your code examples as well.
 
Hi RX

I just do this manually so no code examples I'm afraid

Always thought it would work well in an automated system though.
 

Users who are viewing this thread

Back
Top Bottom