Results 1 to 2 of 2
  1. #1
    Jessica is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2010
    Posts
    1

    Variable Table Names in a Module

    I am trying to import and run a SQL query for multiple DBF files located in one directory. I have been able to get all of the code to work except the RunSQL line. I need "CurrentTable" to be the result of the Import line, not a table name. Is this variable table reference possible?

    Any help would be greatly appreciated. Thanks!


    Function ImportDBFData()

    Dim strPath As String
    Dim strFileName As String
    strPath = "W:\MS_Lists\TEST\DBFS\"
    strTableName = Dir(strPath)
    strFileName = Dir(strPath)
    Do
    DoCmd.TransferDatabase acImport, "dBase III", strPath, acTable, strFileName, Left(strFileName, 7)


    DoCmd.RunSQL "SELECT CurrentTable.PC_ABS_NO, CurrentTable.POSTNET INTO DAY1_FOR_UPLOAD FROM CurrentTable WHERE (CurrentTable.PC_ABS_NO) ORDER BY CurrentTable.PC_ABS_NO;"
    strFileName = Dir ' Get next entry.
    Loop Until strFileName = ""
    RetValue = Msgbox("DBF Files Imported")

    End Function

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sure. Presuming you get the value into a variable, like this:

    "..INTO DAY1_FOR_UPLOAD FROM " & VariableName & " WHERE..."

    Personally I wouldn't bother adding the table name to the field names in the SELECT clause, given the simplicity of the SQL, but you can do the same thing there if desired.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. creating field names in table without typing
    By GHanover in forum Database Design
    Replies: 2
    Last Post: 12-14-2009, 05:13 AM
  2. Query to get column names in a table
    By access in forum Queries
    Replies: 1
    Last Post: 07-06-2009, 05:10 AM
  3. Query to get column names in a table
    By access in forum Forms
    Replies: 1
    Last Post: 07-01-2009, 02:50 PM
  4. Replies: 5
    Last Post: 03-31-2009, 09:16 PM
  5. Replies: 3
    Last Post: 02-20-2009, 02:28 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