Here's the answer to the problem I had above with the help of the other people responding on here:
Sub ADOFromExcelToAccess()
' exports data from the active worksheet to a table in an Access database
' this procedure must be edited before use
Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As Long
' connect to the Access database
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=Path to the database;"
' open a recordset
Set rs = New ADODB.Recordset
rs.Open "Forecast_Items", cn, adOpenKeyset, adLockOptimistic, adCmdTable
' all records in a table
r = 3 ' the start row in the worksheet
Do While Len(Range("Q" & r).Formula) > 0
' repeat until first empty cell in column A
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("UserName") = Range("O" & r).Value
.Fields("Forecast_Date") = Range("P" & r).Value
.Fields("Area") = Range("Q" & r).Value
.Fields("Description_Item") = Range("R" & r).Value
.Fields("Account") = Range("S" & r).Value
.Fields("RRDD") = Range("T" & r).Value
.Fields("CostCenter") = Range("U" & r).Value
.Fields("Fleet") = Range("V" & r).Value
.Fields("ForecastAmount") = Range("W" & r).Value
.Fields("PlanAmount") = Range("X" & r).Value
.Fields("VarianceForecast") = Range("Y" & r).Value
.Fields("Explanation") = Range("Z" & r).Value
' add more fields if necessary...
.Update ' stores the new record
End With
r = r + 1 ' next row
Loop
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
The other code that I have that is supposed to batch all or none if there are errors is. However when an error does occur it is still writing the ones that went through successfully.
Sub ADOFromExcelToAccess()
If MsgBox("This Button Will Submit all Data in the Table to the Right & Clear the Table! Are you sure?", vbYesNo) = vbNo Then Exit Sub
' exports data from the active worksheet to a table in an Access database
' this procedure must be edited before use
Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As Long
' connect to the Access database
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=Filepath.mdb;"
' open a recordset
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open "Forecast_Items", cn, adOpenKeyset, adLockBatchOptimistic, adCmdTable
' all records in a table
r = 3 ' the start row in the worksheet
Do While Len(Range("Q" & r).Formula) > 0
' repeat until first empty cell in column A
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("UserName") = Range("O" & r).Value
.Fields("Forecast_Date") = Range("P" & r).Value
.Fields("Area") = Range("Q" & r).Value
.Fields("Description_Item") = Range("R" & r).Value
.Fields("Account") = Range("S" & r).Value
.Fields("RRDD") = Range("T" & r).Value
.Fields("CostCenter") = Range("U" & r).Value
.Fields("Fleet") = Range("V" & r).Value
.Fields("ForecastAmount") = Range("W" & r).Value
.Fields("PlanAmount") = Range("X" & r).Value
.Fields("VarianceForecast") = Range("Y" & r).Value
.Fields("Explanation") = Range("Z" & r).Value
' add more fields if necessary...
End With
r = r + 1 ' next row
Loop
rs.UpdateBatch 'injects full table from excel into access at the same time, eliminating possible errors with inserting certain rows over others
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
MsgBox ("Data was Submitted Successfully!")
Exit Sub
End Sub