1

I have a module in that imports Excel files into a MS Access database table. I get: MS Access database engine could not find the object 'REPORTCONFIG'. The Table REPORTCONFIG does exist and it is 'picked-up' by the code because just before I import the excel I first empty the table out (which works fine). I have made sure that the tab in my excel is that same name as the Table. (REPORTCONFIG)

This is my module:

Dim MyExcelFileDialogBox As New OpenFileDialog()
        If MyExcelFileDialogBox.ShowDialog = DialogResult.OK Then
            MyExcelFullFileName = MyExcelFileDialogBox.FileName
            MyExcelFile = Dir(MyExcelFileDialogBox.FileName)
            MyExcelFilePath = Path.GetDirectoryName(MyExcelFileDialogBox.FileName)
            ModuleConnection.AccessConnect()
            ModuleTables.DeleteTableContent(MyTableName)
            Dim MyExcelInsertSQL As String = "INSERT INTO [" & MyTableName & "] SELECT * FROM [Excel 12.0;HDR=YES;DATABASE=" & MyExcelFullFileName & "].[" & MyTableName & "];"
            Dim MyCommand As OleDbCommand = New OleDbCommand(MyExcelInsertSQL, MyAccessConnection)
            Try
                MyCommand.ExecuteNonQuery()
                MyCommand.Dispose()
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
            MyAccessConnection.Close()
        End If 

Any help is appreciated.

2
  • Have you tried the query in MS Access by pasting into sql view? Your Excel connect string does not look right to me. Commented Jan 7, 2013 at 16:52
  • The module is working fine for another excel document which I import to a different table. What I find odd, is that if I add the data this way, then it works. <Dim MyExcelInsertSQL As String = "INSERT INTO [REPORTCONFIG] VALUES (10,1,1,'Algemene gegevens','','S','White','Blue','Arial',14,'Bold',0,15,1000,21)> So, yes you would say that the problem then lies with the excel connection string, but as I just mentioned, it is working fine for a different Excel document. Commented Jan 7, 2013 at 17:35

1 Answer 1

1

When using a worksheet as the data source for a query, add a dollar sign ($) after the sheet name so it will be found.

With this simple SELECT query, the db engine complains it can't find REPORTCONFIG:

SELECT *
FROM [Excel 12.0;DATABASE=C:\share\Access\MyWorkBook.xlsx;HDR=YES].[REPORTCONFIG];

However, when using REPORTCONFIG$ in the FROM clause, the following query returns the data without error.

SELECT *
FROM [Excel 12.0;DATABASE=C:\share\Access\MyWorkBook.xlsx;HDR=YES].[REPORTCONFIG$];
Sign up to request clarification or add additional context in comments.

2 Comments

HansUp, the $ did the trick for my document with REPORTCONFIG as tab name but now the other documents with tab name that contains underscores (rpt_bank_krediet_mg_comm_cns) are not importing anymore. Has it to do with the underscores?
HansUp, I found the problem. Problem with variable MyTableName. Thanks again for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.