Results 1 to 7 of 7
  1. #1
    jax1000rr is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2012
    Posts
    26

    Need to download files to users desktop

    Hi,



    I am working on some code that will download a DB to the users desktop and create the directory if it does not already exist.

    the below code works great if you have the absolute paths entered but my issue is that I have 20 users that will need to access this function so I need the code to download the files to that specific users Desktop.

    Is there a way to map to a user specific desktop? I know that in Windows %user% is the users Windows login ID which is what I need to use.

    Here is the code:

    Code:
    Private Sub Form_Open(Cancel As Integer)
    Dim fso As Object
    Dim sSourcePath As String
    Dim sSourceFile As String
    Dim sBackupPath As String
    Dim sBackupFile As String
    Dim db As New Access.Application
    Dim buf As String
    Dim strBu As String
    sSourceFile = "DB.accde"
    sSourcePath = "This is the path to the server and works fine"
    sBackupFile = "DB.accde"
    sBackupPath = "C:\Documents and Settings\%username%\Desktop\Tracker\"
    buf = "C:\Documents and Settings\%username%\Desktop\" & "\Tracker\"
    Set fso = CreateObject("Scripting.FileSystemObject")
    fso.CopyFile sSourcePath & sSourceFile, sBackupPath & sBackupFile, True
    Set fso = Nothing
    DoCmd.Close acForm, "frmDataProcessing"
    End Sub

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    This should be close.

    Code:
    Private Sub Form_Open(Cancel As Integer)
       Dim fso As Object
       Dim sSourcePath As String
       Dim sSourceFile As String
       Dim sBackupPath As String
       Dim sBackupFile As String
       Dim db As New Access.Application
       '   Dim buf As String
       Dim strBu As String
       Dim UName As String
    
    
       UName = Environ("UserName")
       sSourceFile = "DB.accde"
       sSourcePath = "This is the path to the server and works fine"
       sBackupFile = "DB.accde"
       sBackupPath = "C:\Documents and Settings\" & UName & "\Desktop\Tracker\"
    
       'check if dir exists
       If Dir(sBackupPath) = "" Then
          ' No? then make it
          MkDir sBackupPath
       End If
       
       '   buf = "C:\Documents and Settings\" & UName & "\Desktop\Tracker\"
       Set fso = CreateObject("Scripting.FileSystemObject")
       fso.CopyFile sSourcePath & sSourceFile, sBackupPath & sBackupFile, True
       Set fso = Nothing
       DoCmd.Close acForm, "frmDataProcessing"
    End Sub

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,601
    I use Environ("USERNAME") - yes, type it EXACTLY as shown - to get the user's network login.

    EDIT: And Steve got there first!
    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.

  4. #4
    jax1000rr is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2012
    Posts
    26
    Quote Originally Posted by ssanfu View Post
    This should be close.

    Code:
    Private Sub Form_Open(Cancel As Integer)
       Dim fso As Object
       Dim sSourcePath As String
       Dim sSourceFile As String
       Dim sBackupPath As String
       Dim sBackupFile As String
       Dim db As New Access.Application
       '   Dim buf As String
       Dim strBu As String
       Dim UName As String
    
    
       UName = Environ("UserName")
       sSourceFile = "DB.accde"
       sSourcePath = "This is the path to the server and works fine"
       sBackupFile = "DB.accde"
       sBackupPath = "C:\Documents and Settings\" & UName & "\Desktop\Tracker\"
    
      'check if dir exists
       If Dir(sBackupPath) = "" Then
          ' No? then make it
          MkDir sBackupPath
       End If
       
       '   buf = "C:\Documents and Settings\" & UName & "\Desktop\Tracker\"
       Set fso = CreateObject("Scripting.FileSystemObject")
       fso.CopyFile sSourcePath & sSourceFile, sBackupPath & sBackupFile, True
       Set fso = Nothing
       DoCmd.Close acForm, "frmDataProcessing"
    End Sub
    Thank you to the both of you, this is EXACTLY what I was looking for. One last question; if I want to copy all files from sSourcePath, how could I do that?

    Thanks again!

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,601
    Copy all files to the same destination? Possibly asterisk (*) wildcard will accommodate that. Works for me. 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.

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    *.* will copy all files.

    *.accde will copy files where the extension is "accde".

  7. #7
    jax1000rr is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2012
    Posts
    26
    Thanks to all who replied. I would be lost if it were not for this forum!.

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

Similar Threads

  1. FTP download... then FTP delete
    By redbull in forum Programming
    Replies: 4
    Last Post: 07-17-2012, 02:46 PM
  2. Keep users from getting into the raw data files
    By boywonder in forum Database Design
    Replies: 2
    Last Post: 08-20-2011, 09:13 AM
  3. .mdb Download Problem
    By DBCox in forum Access
    Replies: 5
    Last Post: 07-25-2011, 11:31 AM
  4. Replies: 1
    Last Post: 02-21-2011, 09:55 PM
  5. ODBC Client download
    By indira in forum Import/Export Data
    Replies: 1
    Last Post: 12-25-2010, 03:16 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