Import Data From Different User's Documents Folder

EnginerdUNH
StarLounger
Posts: 88
Joined: 14 Aug 2019, 00:12

Import Data From Different User's Documents Folder

Post by EnginerdUNH »

Hi,

I am working on a database where I am trying to add the functionality for people to be able to "batch add" data to the database from a .xlsx file that will be stored locally in a specific folder within their My Documents folder. Currently, I am using the following code and I am getting an error that no .xlsx file can be found.

Code: Select all

DoCmd.OpenQuery "qryDeleteVIRListImport"
            
            Dim strFolder As String
            Dim strFile As String
            strFolder = "C:\Users\" & User & "\Documents\VIR Database Imports"
            strFile = Dir(strFolder & "*xlsx")
            If strFile = "" Then
                MsgBox "There is no .xlsx file in the folder!", vbExclamation
                Exit Sub
            End If
            DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12Xml, _
            "VIRListImport", strFolder & strFile, True
Any help that you can give me to figure out why this code isn't working would be greatly appreciated.

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Import Data From Different User's Documents Folder

Post by HansV »

There should be a backslash at the end of the path:

Code: Select all

            strFolder = "C:\Users\" & User & "\Documents\VIR Database Imports\"
Best wishes,
Hans

EnginerdUNH
StarLounger
Posts: 88
Joined: 14 Aug 2019, 00:12

Re: Import Data From Different User's Documents Folder

Post by EnginerdUNH »

ahhh yes, I forget about that sometimes