Sandra Smith
asked on
2003 Excel import not working in ACCESS 2010
I am testing databases to get ready for migration to ACCESS 2010. however, many of the datasbases I did not create so am having issues. Below module apparenlty worked in ACCESS 2003 but does not work in ACCESS 2010. When I do a Debug Compile, it stops at the rs.Edit line indicating that Method or data member not found. However, this method does seem to exist.
Sandra
Public Function ImportExcelData2()
Dim objFileSystemObject As Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
Dim objFile As Scripting.File
Dim objXLApp As New Excel.Application
Dim objXLWorkbook As Excel.Workbook
Dim objXLSheet As Excel.Worksheet
Dim sAccountNumber As String
Dim sUserDef2CD As String
Dim iRow As Integer
Dim sSQL As String
Dim rs As Recordset
Set objFileSystemObject = New Scripting.FileSystemObject
Set objFolder = objFileSystemObject.GetFol der(SOURCE _IMPORT_FO LDER)
'Import file
For Each objFile In objFolder.Files
Set objXLWorkbook = objXLApp.Workbooks.Open(SO URCE_IMPOR T_FOLDER & "\" & objFile.Name)
Set objXLSheet = objXLWorkbook.Sheets("Shee t1")
iRow = 2
Do
sAccountNumber = Trim(objXLSheet.Cells(iRow , 1))
sUserDef2CD = Trim(objXLSheet.Cells(iRow , 6))
sSQL = "SELECT ACCT_NBR, USER_DEF_2_CD "
sSQL = sSQL & "FROM Accounts "
sSQL = sSQL & "WHERE ACCT_NBR='" & sAccountNumber & "' "
Set rs = CurrentDb.OpenRecordset(sS QL, dbOpenDynaset)
If rs.RecordCount > 0 Then
'Update USER_DEF_2_CD
rs.Edit 'INDICATES METHOD DOES NOT EXIST HERE
rs!USER_DEF_2_CD = sUserDef2CD
rs.Update
End If
iRow = iRow + 1
Loop While sAccountNumber <> ""
Next objFile
objXLWorkbook.Close SaveChanges:=False
Set objXLWorkbook = Nothing
objXLApp.Quit
Set objXLApp = Nothing
CleanExit:
MsgBox "Import Success. " & vbCrLf & iRow & " Excel Rows Processed..."
DoCmd.Hourglass False
DoCmd.Close acForm, "frmProcessing"
Exit Function
ErrHandler:
MsgBox Err.Description
GoTo CleanExit
Resume
End Function
Sandra
Public Function ImportExcelData2()
Dim objFileSystemObject As Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
Dim objFile As Scripting.File
Dim objXLApp As New Excel.Application
Dim objXLWorkbook As Excel.Workbook
Dim objXLSheet As Excel.Worksheet
Dim sAccountNumber As String
Dim sUserDef2CD As String
Dim iRow As Integer
Dim sSQL As String
Dim rs As Recordset
Set objFileSystemObject = New Scripting.FileSystemObject
Set objFolder = objFileSystemObject.GetFol
'Import file
For Each objFile In objFolder.Files
Set objXLWorkbook = objXLApp.Workbooks.Open(SO
Set objXLSheet = objXLWorkbook.Sheets("Shee
iRow = 2
Do
sAccountNumber = Trim(objXLSheet.Cells(iRow
sUserDef2CD = Trim(objXLSheet.Cells(iRow
sSQL = "SELECT ACCT_NBR, USER_DEF_2_CD "
sSQL = sSQL & "FROM Accounts "
sSQL = sSQL & "WHERE ACCT_NBR='" & sAccountNumber & "' "
Set rs = CurrentDb.OpenRecordset(sS
If rs.RecordCount > 0 Then
'Update USER_DEF_2_CD
rs.Edit 'INDICATES METHOD DOES NOT EXIST HERE
rs!USER_DEF_2_CD = sUserDef2CD
rs.Update
End If
iRow = iRow + 1
Loop While sAccountNumber <> ""
Next objFile
objXLWorkbook.Close SaveChanges:=False
Set objXLWorkbook = Nothing
objXLApp.Quit
Set objXLApp = Nothing
CleanExit:
MsgBox "Import Success. " & vbCrLf & iRow & " Excel Rows Processed..."
DoCmd.Hourglass False
DoCmd.Close acForm, "frmProcessing"
Exit Function
ErrHandler:
MsgBox Err.Description
GoTo CleanExit
Resume
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER