Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DoCmd.TransferSpreadsheet Still Won't Work. Run-time Error 2391 1

Status
Not open for further replies.

Fattire

Technical User
Nov 30, 2006
127
0
0
US
There have been a lot of posts on Run-time error 2391 but I have never seen an answer to it:

Code:
Private Sub CMD_IMPORT_NEW_DATA_Click()

    Dim varDate As String
    Dim varSpecification As String
    Dim varTable As String
    Dim strInputFileName As String

    varTable = "TBL_AR_AGING"
    varDate = Format(Format(Now(), "DDMMMYYYY_HhMmSs_AMPM"), ">")
    
    strInputFileName = ahtCommonFileOpenSave( _
                    OpenFile:=False, _
                    DialogTitle:="Please select the excel file you want to import...", _
                    Flags:=ahtOFN_HIDEREADONLY)

    If (strInputFileName & "") = "" Then
    Else
    
    'strInputFileName = Chr(34) & strInputFileName & Chr(34)
        
    DoCmd.OpenQuery "QDEL_AR_AGING"
    
    DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, varTable, strInputFileName
    
    End If

This produces an error: Field 'F1' doesn't exist in destination table "TBL_AR_AGING"

The field names are the same in the excel spreadsheet as the table (in fact the table was made from an import of the same file), there are no spaces in the directory of strInputFileName, I've tried every Excel type (4 through 9), and when I import the excel file by going through the wizard it works every time - just not via VBA code.

Any help would be appreciated.
 
Does your XLS contain fieldnames for the first row?

if So try adding comma 1 on the end...
Code:
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, varTable, strInputFileName[b], 1[/b]

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Dude I've have been trying to figure that out for a week now, right under my nose - awesome - ty much.
 
In fact,
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, varTable, strInputFileName, [!]True[/!]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
no worries, that's that we're here for ;-)

Funny how somethings are so easy when you know how, and seem imposible when you don't [lol]

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
yes, 1 = true , though not always, switching between so many languages, I get confused very easily!

It works so I don't question it, but I'd go with PHV, he's normally right about these things ;-)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Thanks PHV - now I just have to come up with some lame excuse to my boss as to why I'm an idiot for not reading the specs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top