Results 1 to 13 of 13
  1. #1
    dinsey90 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    29

    Create Folder based on field names


    Hi,

    I need my database to create a new folder on my computer and name it based on the fields within the form it comes from. I have included a picture of the form fields below. When i click the add quote button it saves the quote to the quote table. I need it to also create a folder on my computer and name it using the Quote_Num, Client_Name & Job_Name fields combined with a hyphen in between?
    Click image for larger version. 

Name:	newquote.JPG 
Views:	20 
Size:	123.9 KB 
ID:	30481
    Thanks
    J

  2. #2
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Check out the MkDir Statement .

    You would concatenate Quote_Num, Client_Name & Job_Name fields, then use that to create the new folder.

  3. #3
    dinsey90 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    29
    Sorry I'm pretty new to this, how would i go about concatenating the field names and creating the folder?

    Thanks

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You would use VBA to do something like
    Code:
    Dim MyQuotePath As String
    Dim NewFolderName As String
    
     'Path to where you want to create the new folder
    MyQuotePath = "C:\AllQuotes\dinsey90\"
    
    'the new folder name
    NewFolderName = Quote_Num & "_" & Client_Name & "_" & Job_Name 
    
    'create the folder
    MkDir MyQuotePath & NewFolderName
    (doing this from memory )

  5. #5
    dinsey90 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    29
    Thanks ssanfu, i tried that but it is coming up with an error on the last line MkDir MyQuotePath & NewFolderName
    Also will this create the folder name based on the details in the form that the user would be entering in to?

  6. #6
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Ssanfu's code works. Please post the entire subroutine that you are using.

  7. #7
    dinsey90 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    29
    Hi, Once i added it in i am now getting this error on both buttons in my form when trying to add a quote or just close without saving? I dont know how to resolve this, i tried just commenting out the code but it still occurs.


    Click image for larger version. 

Name:	macrofolder.JPG 
Views:	15 
Size:	37.5 KB 
ID:	30508
    Click image for larger version. 

Name:	code.JPG 
Views:	15 
Size:	35.1 KB 
ID:	30509

  8. #8
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    I get that error sometimes too, not sure what causes it. I resolve it by going into form design, going to the event, and clicking on the three dots. This seems to reconnect the event procedure to the VBA module.

  9. #9
    dinsey90 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    29
    Hi aytee,

    I've tried that a few times but no joy, it just keeps coming up every time i click the button?

  10. #10
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    These two lines should be at the top of every module
    Code:
    Option Compare Database
    Option Explicit
    Have you tried Debug /Compile?? The error should be in the "frmNewQuote" module.


    BTW, in the lines
    Code:
    DoCmd.Close acForm, "frmNewQuote", acSaveYes
    
    DoCmd.Close acForm, "frmNewQuote", acSaveNo
    the acSaveYes & acSaveNo do not do what you think. These parameters are for saving DESIGN changes of the form, NOT saving the data.

    In code, you could switch a form to design mode, change the form by adding or deleting an object, changing formatting, colors, etc and close the form. THEN you would use those parameters to save the form design change(s).......


    You could post your dB for analysis......(do compact & repair, then zip it)

  11. #11
    dinsey90 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    29
    Thanks so much, the folder is now creating for me Is there anyway to create sub folders in this from the code? Thanks

  12. #12
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Sure... create the new sub folder path, then use the MkDir command again.

  13. #13
    securitywyrm is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    97
    My code for something similar is

    Code:
    Private Sub Command69_Click()
    If Len(Dir(CurrentProject.path & "\" & "RecordFiles" & "\" & Identification, vbDirectory)) = 0 Then
       MkDir CurrentProject.path & "\" & "RecordFiles" & "\" & Identification
    End If
    If Len(Dir(CurrentProject.path & "\" & "RecordFiles" & "\" & Identification & "\" & ID, vbDirectory)) = 0 Then
       MkDir CurrentProject.path & "\" & "RecordFiles" & "\" & Identification & "\" & ID
    End If
    Dim path As String
    path = CurrentProject.path & "\" & "RecordFiles" & "\" & Identification & "\" & ID & "\"
    Shell "cmd /C start """" /max """ & path & """", vbHide
    End Sub
    What this does: It checks if the first layer folder exists, if not then it creates it. THEN it checks if the second layer folder exists, and if not creates it, then opens the second layer folder.

    And yes I know that this file structure is horrible because changing a person's name will break the link to all their files, but I have to write this assuming at some point in the future they're going to lose the access file and thus need to dig through all the files manually.

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

Similar Threads

  1. Replies: 7
    Last Post: 01-19-2016, 05:28 PM
  2. combobox based on folder names
    By sdel_nevo in forum Programming
    Replies: 3
    Last Post: 11-18-2014, 12:40 PM
  3. Replies: 7
    Last Post: 08-20-2014, 03:00 AM
  4. Browse and Open Folder Based on Matching Form Field
    By Tomfernandez1 in forum Access
    Replies: 11
    Last Post: 02-26-2013, 01:04 PM
  5. Replies: 4
    Last Post: 09-18-2012, 11:30 PM

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