Share via

Import only specific column to Access

Anonymous
2018-02-12T19:29:31+00:00

I have the following code in Access that will import files into a table and everything works fine but I'd like to build on it and only bring in specific columns.  Right now all the columns are coming in, these are external files so sometimes some of the fields are missing or others are added which kills the process (doesn't happen all the time but annoying when it does).  What and where can I add a code to import i.e. BatchId, MemberId?

Function COMWEL15()

    Dim strPathFile As String, strFile As String, strPath As String

    Dim strTable As String

    Dim blnHasFieldNames As Boolean

 ' Change this next line to True if the first row in EXCEL worksheet has field names

    blnHasFieldNames = True

 ' Path to the folder that contains the files

    strPath = "F:\HOME\COMMON\2018\COMWEL15_"

 ' Table into which the data are to be imported

    strTable = "COMWEL15_MASTER_RESULTS"

 'Path and FileName

    strFile = Dir(strPath & "*.csv")

    Do While Len(strFile) > 0

        strPathFile = strPath & strFile

    DoCmd.TransferText acImportDelim, , _

         strTable, strPathFile, blnHasFieldNames

       strFile = Dir()

    Loop

Call MDWEL

End Function

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Tom van Stiphout 40,211 Reputation points MVP Volunteer Moderator
    2018-02-12T20:46:15+00:00

    Create an Import Specification, and then set that argument in DoCmd.TransferText.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments