I originally asked this question at:
thread700-1483500.
Does anyone have an idea as to what the cause would be?
I am creating several tables in code based on the worksheets that will be imported from Excel. I now have (it seems) everything working except for this one thing.
For some reason, even though I set every field as "text", Access is still creating "_ImportErrors" tables. I can't for the life of me figure it out.
Every time it is on the "House #" field. That field is storing the house number of addresses.
Here is the code I have that is working on everything except for the House # field - and it's just a few records that are giving the issue:
And here are the data values that are causing the "ImportErrors":
[UL]
[LI]130A[/LI]
[LI]144-23[/LI]
[LI]71-37[/LI]
[LI]39 11[/LI]
[LI]116P[/LI]
[LI]380A[/LI]
[/UL]
Here is the import error description (same for all records):
Any thoughts/ideas as to how to get around these import errors?
--
"If to err is human, then I must be some kind of human!" -Me
thread700-1483500.
Does anyone have an idea as to what the cause would be?
I am creating several tables in code based on the worksheets that will be imported from Excel. I now have (it seems) everything working except for this one thing.
For some reason, even though I set every field as "text", Access is still creating "_ImportErrors" tables. I can't for the life of me figure it out.
Every time it is on the "House #" field. That field is storing the house number of addresses.
Here is the code I have that is working on everything except for the House # field - and it's just a few records that are giving the issue:
Code:
Public Sub ExcelToDatabase()
Dim wb As Workbook
Dim ws As Worksheet
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As Field
Dim c As Integer 'Excel Column
Dim intMaxCol As Integer 'Excel worksheet furthest right column with something in it
Dim intMaxRow As Integer 'Excel worksheet lowest row with data.
Dim strWbName As String 'Store name of workbook
Dim z As Integer 'Test to create tons of extra fields so no headaches with imports
Dim x As Integer 'To count through a few extra columns just in case (when matching up field names)
Dim intCntTbl
Set wb = Workbooks.Open(Forms!frmImport!txtXlFile)
Set db = CurrentDb
strWbName = Forms!frmImport!txtXlFile
For Each tdf In db.TableDefs
With tdf
If InStr(.Name, "sys") Then
ElseIf InStr(.Name, "tbl") Then
Else
DoCmd.SetWarnings False
DoCmd.DeleteObject acTable, tdf.Name
DoCmd.SetWarnings True
End If
End With
Next tdf
intCntTbl = 0
For Each ws In wb.Worksheets
If InStr(ws.Name, "Intro") Then
ElseIf InStr(ws.Name, "Terms") Then
Else
intCntTbl = intCntTbl + 1
ws.Activate
ws.Cells.Select
ws.Cells.NumberFormat = xlText
intMaxCol = Excel.Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
intMaxRow = Excel.Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Row
Set tdf = db.CreateTableDef(ws.Name)
c = 1
With tdf
CellLoop:
Do While Not (ws.Cells(1, c) = vbNullString)
.Fields.Append .CreateField(ws.Cells(1, c), dbText, 30)
c = c + 1
Loop
If ws.Cells(1, c) = vbNullString Then
.Fields.Append .CreateField("F" & c, dbText, 30)
c = c + 1
If ws.Cells(1, c) = vbNullString Then
.Fields.Append .CreateField("F" & c, dbText, 30)
c = c + 1
If ws.Cells(1, c) = vbNullString Then
.Fields.Append .CreateField("F" & c, dbText, 30)
c = c + 1
If ws.Cells(1, c) = vbNullString Then
Else
GoTo CellLoop
End If
Else
GoTo CellLoop
End If
Else
GoTo CellLoop
End If
Else
GoTo CellLoop
End If
z = c
For z = c To 50
.Fields.Append .CreateField("F" & z, dbText, 30)
Next z
db.TableDefs.Append tdf
Set fld = Nothing
Set tdf = Nothing
End With 'tdf
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, ws.Name, strWbName, True, ws.Name & "$"
End If 'ws.Name
Next ws
MsgBox intCntTbl & " worksheets imported!", vbInformation, "Import Complete"
ExitSub:
Excel.Application.DisplayAlerts = False
wb.Close
Set wb = Nothing
Excel.Application.DisplayAlerts = False
db.Close
Set db = Nothing
Exit Sub
ErrHandle:
ErrTalk (Forms!frmImport!txtImportID)
Resume ExitSub
End Sub
And here are the data values that are causing the "ImportErrors":
[UL]
[LI]130A[/LI]
[LI]144-23[/LI]
[LI]71-37[/LI]
[LI]39 11[/LI]
[LI]116P[/LI]
[LI]380A[/LI]
[/UL]
Here is the import error description (same for all records):
Type Conversion Failure
Any thoughts/ideas as to how to get around these import errors?
--
"If to err is human, then I must be some kind of human!" -Me