This one is not going to be easy! I need some help to know if what I'm doing is even possible. I have a lot of files that create a tab that needs to be imported into a table in access. The code I have so far imports the data into the access table, and works like a charm. The issue is that sometimes there's an error (I haven't been able to narrow this down to the reason why yet). Can we somehow modify this code to tell us if there's an error and if so which line or column or both? Let me know if you need any more specifics. Thanks for any help!
Code:
Option Explicit
Sub AccImport()
Dim lrow As Integer
Dim rng As String
Dim acc As New Access.Application
If Sheets("Input").Range("M1").Value = ChrW(&H2713) Then 'testing if it's already been imported into access.
MsgBox ("The data has already been imported. Exiting macro...")
Exit Sub
Else
'Excel range for data that needs imported to access
lrow = Sheets("Summary").Cells(Rows.Count, 1).End(xlUp).Row
rng = "Summary$A1:G" & lrow
Find access database and import
acc.OpenCurrentDatabase "C:\Users\Test\Finalfile.accdb"
acc.DoCmd.TransferSpreadsheet _
TransferType:=acImport, _
SpreadSheetType:=acSpreadsheetTypeExcel12Xml, _
TableName:="tblSummary", _
Filename:=Application.ActiveWorkbook.FullName, _
HasFieldNames:=True, _
Range:=rng
acc.CloseCurrentDatabase
acc.Quit
Set acc = Nothing
'Mark completed on the excel tab
Sheets("Input").Range("M1").Value = ChrW(&H2713)
MsgBox ("Summary has been imported.")
End If
End Sub