Results 1 to 2 of 2
  1. #1
    thart21 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    83

    Make directory or folder

    I'm so close with this one but need a little assistance in creating a new folder in my directory based on the value selected in the combo box.


    Private Sub cmdSeason_Click()
    On Error GoTo Err_cmdSeason_Click


    Dim stDocName As String
    stDocName = "qSourceData_AllSeasons"
    Const DownloadPath As String = "FilePathName\"

    MkDir DownloadPath & Left(Me![cboSeason].Value, 2)
    I have also tried Left(Forms!frmRunDP_worksheets!cboSeason.Value, 2)

    'On Error GoTo ErrorRoutine

    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qSourceData_AllSeasons", _
    DownloadPath & Left(Me![cboSeason].Value, 2) & "\" & Left(Forms!frmRunDP_worksheets!cboSeason.Value, 2) & Right(Forms!frmRunDP_worksheets!cboSeason.Value, 2) & "_" & "Download" & ".xls"


    Exit_cmdSeason_Click:
    Exit Sub
    Err_cmdSeason_Click:
    MsgBox Err.Description
    Resume Exit_cmdSeason_Click

    End Sub

    I'm getting a file/path error when running this one. the TransferSpreadsheet part works perfectly, just need to get the folder created if there isn't one (Have the If Else code ready to go)
    Would appreciate any tips on getting this work.

    Thanks
    Toni

  2. #2
    thart21 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    83
    Think I got it so time to share

    Private Sub cmdSeason_Click()
    On Error GoTo Err_cmdSeason_Click
    Dim stDocName As String
    stDocName = "qSourceData_AllSeasons"
    Const DownloadPath As String = "FilePathName\"

    'Check to see if there is a folder for the Season selected in the drop down menu
    'If not, create the folder, run query and export to the new folder

    If Dir "FilePathName\"
    & Left(Me![cboSeason].Value, 2) & Right(Me![cboSeason].Value, 2), vbDirectory) = "" Then
    MkDir "FilePathName\"
    & Left(Me![cboSeason].Value, 2) & Right(Me![cboSeason].Value, 2)
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qSourceData_AllSeasons", _
    DownloadPath & Left(Me![cboSeason].Value, 2) & Right(Me![cboSeason].Value, 2) & "\" & Left(Forms!frmRunDP_worksheets!cboSeason.Value, 2) & Right(Forms!frmRunDP_worksheets!cboSeason.Value, 2) & "_" & "Download" & ".xls"

    Else

    'If folder already exists, run query and export to existing Season folder

    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qSourceData_AllSeasons", _
    DownloadPath & Left(Me![cboSeason].Value, 2) & Right(Me![cboSeason].Value, 2) & "\" & Left(Forms!frmRunDP_worksheets!cboSeason.Value, 2) & Right(Forms!frmRunDP_worksheets!cboSeason.Value, 2) & "_" & "Download" & ".xls"

    End If

    MsgBox "File has been exported, Open Excel file?", vbYesNo


    'DoCmd.OpenQuery stDocName, acNormal, acEdit
    Exit_cmdSeason_Click:
    Exit Sub
    Err_cmdSeason_Click:
    MsgBox Err.Description
    Resume Exit_cmdSeason_Click

    End Sub

    Cheers!

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

Similar Threads

  1. Creating Viewport into a folder
    By dragondata in forum Access
    Replies: 2
    Last Post: 03-26-2010, 07:15 PM
  2. New directory with the name from field
    By np1111 in forum Programming
    Replies: 14
    Last Post: 02-25-2010, 07:06 AM
  3. Replies: 0
    Last Post: 12-16-2009, 09:28 AM
  4. Displaying images from another folder
    By w3leon in forum Access
    Replies: 0
    Last Post: 01-30-2009, 06:18 PM
  5. Replies: 0
    Last Post: 09-18-2006, 08:37 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