B
BTU_needs_assistance_43
I'm running code to import columns of information from Excel to an Access
table and the program gets far enough to open the Excel file in a new window
but then i get this '3421' error "Data Type Conversion Error" message. I've
checked the source Excel cells and matched them to the same type of table
cells in Access (ex: number to number, text to text, etc...). The range is
set to start at the first cell that contains data. The table, file,
worksheet, and database are all right. What am I doing wrong?
_____________________________________________________________________
Private Sub Command6_Click()
Dim lngColumn As Long
Dim xlx As Object, xlw As Object, xls As Object, xlc As Object
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim blnEXCEL As Boolean
Dim strLocation As String
blnEXCEL = True
On Error Resume Next
Set xlx = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Set xlx = CreateObject("Excel.Application")
blnEXCEL = True
End If
Err.Clear
On Error GoTo 0
xlx.Visible = True
Set xlw = xlx.Workbooks.Open(C:\My Documents\Excel.xls, , True)
Set xls = xlw.Worksheets("Cast")
Set xlc = xls.Range("B5") ' this is the first cell that contains data
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("Cast Reports", dbOpenDynaset, dbAppendOnly)
Do While xlc.Value <> ""
rst.AddNew
For lngColumn = 0 To rst.Fields.Count - 1
rst.Fields(lngColumn).Value = xlc.Offset(0, lngColumn).Value
Next lngColumn
rst.Update
Set xlc = xlc.Offset(1, 0)
Loop
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
Set xlc = Nothing
Set xls = Nothing
xlw.Close False
Set xlw = Nothing
If blnEXCEL = True Then xlx.Quit
Set xlx = Nothing
End Sub
table and the program gets far enough to open the Excel file in a new window
but then i get this '3421' error "Data Type Conversion Error" message. I've
checked the source Excel cells and matched them to the same type of table
cells in Access (ex: number to number, text to text, etc...). The range is
set to start at the first cell that contains data. The table, file,
worksheet, and database are all right. What am I doing wrong?
_____________________________________________________________________
Private Sub Command6_Click()
Dim lngColumn As Long
Dim xlx As Object, xlw As Object, xls As Object, xlc As Object
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim blnEXCEL As Boolean
Dim strLocation As String
blnEXCEL = True
On Error Resume Next
Set xlx = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Set xlx = CreateObject("Excel.Application")
blnEXCEL = True
End If
Err.Clear
On Error GoTo 0
xlx.Visible = True
Set xlw = xlx.Workbooks.Open(C:\My Documents\Excel.xls, , True)
Set xls = xlw.Worksheets("Cast")
Set xlc = xls.Range("B5") ' this is the first cell that contains data
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("Cast Reports", dbOpenDynaset, dbAppendOnly)
Do While xlc.Value <> ""
rst.AddNew
For lngColumn = 0 To rst.Fields.Count - 1
rst.Fields(lngColumn).Value = xlc.Offset(0, lngColumn).Value
Next lngColumn
rst.Update
Set xlc = xlc.Offset(1, 0)
Loop
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
Set xlc = Nothing
Set xls = Nothing
xlw.Close False
Set xlw = Nothing
If blnEXCEL = True Then xlx.Quit
Set xlx = Nothing
End Sub