Results 1 to 7 of 7
  1. #1
    DC CS is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Vaalpark, South Africa
    Posts
    63

    Saving files to a local PC

    Hi.
    I am looking for a sample code or advise on how to save a file from a remote desktop server to the user's local PC, using VBA

    The Access database front end is located on the server (so is the back end). The user connects to the remote server via VPN and then logs into the RDP server.
    Everything is running smoothly, but when it comes to saving certain documents, the database saves it to the remote server's "C\Temp".
    I need to save the document to the users' "C:\Temp". There are several users that connects to the server and run the database at any given time.

    I have used the below code I found on the internet to test, but it is not working. The code displays the error message:


    Dim FSO: Set FSO = CreateObject("Scripting.FileSystemObject")
    Dim strFile: strFile = "c:\temp\mytestfile.txt"
    Dim strTargetPath: strTargetPath = "\\10.200.11.10\Temp"


    'verify the remote folder exists
    If FSO.FolderExists(strTargetPath) Then


    'verify the source file exists
    If FSO.FileExists(strFile) Then
    'use FSO.MoveFile <Source>,<Target> if you want to move instead of copy
    FSO.CopyFile strFile, strTargetPath
    Else
    MsgBox "ERROR: Source FIle does not exist or is not accessible."
    End If
    Else
    MsgBox "ERROR: Target Folder does not exist or is not accessible."
    End If

    This is the first time I have to save a file from a server to local disk, so any advice is greatly appreciated.

    Thanks

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,398
    no error message supplied

    but my guess would be you are only providing a target path which does not include the file name

    Also looks to me like you are trying to copy from a local folder to the server folder - the opposite of the thread header.

    For the future, enclose your code with the code tags to preserve indentation (highlight the code and click the <> button). Code that is not indented is difficult to read and may explain why you have had a number of views but no responses until now

  3. #3
    DC CS is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Vaalpark, South Africa
    Posts
    63
    Quote Originally Posted by CJ_London View Post
    no error message supplied

    but my guess would be you are only providing a target path which does not include the file name

    Also looks to me like you are trying to copy from a local folder to the server folder - the opposite of the thread header.

    For the future, enclose your code with the code tags to preserve indentation (highlight the code and click the <> button). Code that is not indented is difficult to read and may explain why you have had a number of views but no responses until now

    Hi. I am including the code again. You were right, I switched the source and target path:

    HTML Code:
    Dim FSO: Set FSO = CreateObject("Scripting.FileSystemObject")Dim strFile: strFile = "c:\temp\mytestfile.txt"Dim strTargetPath: strTargetPath = "\\10.200.11.4\Temp"
    
    'verify the remote folder existsIf FSO.FolderExists(strTargetPath) Then'verify the source file existsIf FSO.FileExists(strFile) Then'use FSO.MoveFile <Source>,<Target> if you want to move instead of copyFSO.CopyFile strFile, strTargetPathElseMsgBox "ERROR: Source FIle does not exist or is not accessible."End IfElseMsgBox "ERROR: Target Folder does not exist or is not accessible."End If
    Running the above code, I get the error "ERROR: Target Folder does not exist or is not accessible."

    The sourcefile is fine - no error.

    Thanks

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    Actually, # icon is for CODE tags. Note that your code has not retained readability.

    Code works for me but I am not trying to copy to or from a server via VPN.

    The IP address path is for the user's local PC? How do you determine that identifier?

    Could be can't do what you want because this is a VPN connection. If I understand how VPN works, the local computer is not really part of the VPN. It's why VPN stands for Virtual Private Network. Backslash in path indicates an internal path as you see in Windows Explorer for your PC and LAN. You have established a virtual presence within the VPN, the PC itself is outside the VPN.

    Assuming folder permissions are granted, can certainly programmatically copy files between local PC drive and LAN server with no VPN involved.

    When you are logged in through VPN, does Windows Explorer on server 'see' your PC file structure? Can you manually copy/paste a file from server to PC folder?
    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
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,398
    Actually, # icon is for CODE tags.
    my bad - thinking of a different forum

    also think target string needs an ending \

    you have "\\10.200.11.10\Temp"

    think it should be

    "\\10.200.11.10\Temp"

  6. #6
    DC CS is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Vaalpark, South Africa
    Posts
    63
    The remote server is accessed with VPN, so I assume it is not possible to save from the remote server directly to the user local disk.
    I am now using E-Mail to mail the created documents to the user, which works fine. The application saves a copy to the server as well, so if a Mail gets lost, I can always retrieve the document from the server.

    Thanks for the help.

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    CJ, quite possibly backslash is actually in OP's code but posting to thread drops ending backslash when not between CODE tags. See result in your own post.

    Either use CODE tags or go to Advanced edit and uncheck "Automatically parse links in text" - every time you edit post.
    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. Replies: 0
    Last Post: 02-06-2021, 05:25 PM
  2. Replies: 2
    Last Post: 10-14-2016, 12:27 PM
  3. saving access database to local drive
    By denni34 in forum Access
    Replies: 4
    Last Post: 10-23-2015, 09:03 AM
  4. saving data from Attachment field to local drive
    By saleemsadique in forum Access
    Replies: 5
    Last Post: 01-21-2014, 06:52 PM
  5. Saving Module Code to Text Files
    By ioMatt in forum Modules
    Replies: 2
    Last Post: 07-02-2011, 08:18 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