Results 1 to 6 of 6
  1. #1
    uaguy3005 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    45

    FileDialog Question

    I've added a button on my form. The idea is the user will click the button and a file dialog box will open. The user will select a file (PDF) and I would like to take the file and save it to a different network location with a different name.

    I don't think I'm using the File Dialog application correctly. Any suggestions?

    Private Sub Upload1stTraining_Click()
    Dim fd As FileDialog
    Dim objfl As Variant
    Dim strDestFile As String


    Dim strUploadFile As String
    Dim strTrainingName As String

    strTrainingName = Me.ID & " - " & Me.Line & " 1st.pdf"
    strDestFile = "S:\QUALITY\QUALITY ALERTS\Training Records\" & strTrainingName

    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    With fd
    .ButtonName = "Select"
    .AllowMultiSelect = False
    .Filters.Add "PDF", "*.pdf"
    .Title = "Choose Transactions file to import"
    .InitialView = msoFileDialogViewDetails
    .Show
    For Each objfl In .SelectedItems
    strUploadFile = objfl
    Next objfl
    On Error GoTo 0
    End With

    Set fd = Nothing

    ' Enter code to save the strUploadFile to the strDestFile

    Me.Ctl1st_Shift_Training = True

    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Why doesn't it work - error message, wrong results, nothing?

    The loop to build strUploadFile is not correct. However, I don't think building a string of the document names will serve to do want you want. Instead of building string within the loop, copy the file to the new location. Review http://www.rondebruin.nl/folder.htm
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    uaguy3005 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    45
    Quote Originally Posted by June7 View Post
    Why doesn't it work - error message, wrong results, nothing?

    The loop to build strUploadFile is not correct. However, I don't think building a string of the document names will serve to do want you want. Instead of building string within the loop, copy the file to the new location. Review http://www.rondebruin.nl/folder.htm
    Actually, I got that code to work last night. I was getting an error on FileCopy strUploadFile, strDestFile. I'm not sure what changed, perhaps a typo, but I redid that part and it started working. But to be honest, I haven't really figured out how this code works yet. Any information you can provide would be appreciated.

    Private Sub Upload1stTraining_Click()
    Dim fd As FileDialog
    Dim objfl As Variant
    Dim strDestFile As String
    Dim strUploadFile As String
    Dim strTrainingName As String

    strTrainingName = Me.ID & " - " & Me.Line & " 1st.pdf"
    strDestFile = "S:\QUALITY\QUALITY ALERTS\Training Records\" & strTrainingName

    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    With fd
    .ButtonName = "Select"
    .AllowMultiSelect = False
    .Filters.Add "PDF", "*.pdf"
    .Title = "Choose Transactions file to import"
    .InitialView = msoFileDialogViewDetails
    .Show
    For Each objfl In .SelectedItems
    strUploadFile = objfl
    Next objfl
    On Error GoTo 0
    End With
    Set fd = Nothing

    FileCopy strUploadFile, strDestFile

    ' Flips a checkbox to true alerting the user the file has been succesfully uploaded.
    Me.Ctl1st_Shift_Training = True
    End Sub

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    The code allows you to select multiple files in the dialog and then copies all the selected files to the new location? I would be surprised if that works. From what I see only one file would be copied but if it's really doing what you want, then congratulations!

    Use debugging techniques to help you understand the code. Refer to link at bottom of my post. Set a breakpoint and step through the code.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    uaguy3005 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    45
    Quote Originally Posted by June7 View Post
    The code allows you to select multiple files in the dialog and then copies all the selected files to the new location? I would be surprised if that works. From what I see only one file would be copied but if it's really doing what you want, then congratulations!

    Use debugging techniques to help you understand the code. Refer to link at bottom of my post. Set a breakpoint and step through the code.
    Actually that's correct. I only want to allow 1 file to be copied, but this was the only code I could find that would work the way I would like. Is there a better dialog box to open that would allow only 1 selection to be made? In excel I would use the Application.GetSaveAsDialog but that same functionality doesn't work in Access 2007.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    I see now that you set AllowMultiSelect to False. No, I don't know any other method.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Using FileDialog to export to Excel
    By zapouk in forum Import/Export Data
    Replies: 2
    Last Post: 04-20-2012, 04:31 AM
  2. FileDialog
    By Tomfernandez1 in forum Programming
    Replies: 9
    Last Post: 04-13-2011, 03:45 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