The old Excel import problem.
I too also had to struggle with issue, but I was able to solve the problem, or at least find a work around solution.
I discovered that if you have a link to an excel tabel and run a query to import the Excel data into an Access table, well, it will work fine for several attempts and then it will fail.
Turns out that this seems to be a bug in Access/Excel.
My solution, creat a new, temp access table, every time the import is run. This must be a newly named table. Once the data is brought into a one time, temporary Access table, I run a second query to import from the temp access table to my 'working' access table.
Seems like a lot of trouble, but it works every time.
So, I have included the code on how I did this.
Code:
Call this function below:
Private Function LoadTheExcelData() As Integer
'Need to refresh Links to make Excel Work Correctly
Dim MySql As String
Dim TempTableName As String
DoCmd.Hourglass True
DoCmd.SetWarnings False
'On Error Resume Next
Randomize
TempTableName = "tblTemp" & Mid$(Trim$(Str$(Rnd) & " "), 2)
'Remove our working dataset
DoCmd.OpenQuery "qryStep1_DeleteWorkEntries"
'TempTableName = "tblTempxxx"
'Get new data
'Excel Not always behaving, so vary table name
'DoCmd.OpenQuery "qryStep2_ImportWorkEntries"
'1) Move to a new, table
MySql = "SELECT tblWebDataSheet1.* INTO " & TempTableName & " FROM tblWebDataSheet1"
DoCmd.RunSQL MySql
'2) Import from New Temp table
MySql = "INSERT INTO tblWebDataWorkArea SELECT [" & TempTableName & "].* FROM [" & TempTableName & "] "
DoCmd.RunSQL MySql
'3) Remove New Temp table
DoCmd.DeleteObject acTable, TempTableName
DoCmd.SetWarnings True
DoCmd.Hourglass False
DoEvents
MsgBox "Import is done"
End Function
Note:
When I do an import, I make sure all target data dields are 'text' type. That way, the data always get's loaded. I later qun code or a query to validate or move to the true field. That way, null or bad dates and bad nuemric data will not cause the import query to fail.
Hope This Helps,
Hap...
Access Developer
Access based Add-on Solutions
Access Consultants forum