I am treying to move data from an Excel worksheet to Access. My code is below. My program does not like my "Set rs = OpenTable("GL")" line
Option Explicit
Public Const gconConnection = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source='C:\users\c156281\my documents\PLAN\Plan New.accdb'"
Public rsData As DAO.Recordset
Sub PostData()
'TryPostAgain:
'On Error GoTo BadPost
'On Error GoTo 0
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim Stringsql As String
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.Open gconConnection
Dim Sht As Worksheet
Set Sht = Worksheets("ImportSht")
Dim lngFieldNameRow As Long
Dim lngLastPostRow As Long
Dim lngFlagColumn As Long
Dim lngLastColumn As Long
initGlobals
lngFieldNameRow = Sht.Range("ImportHeaderRow").Row
lngLastColumn = 35
Dim strCurrentField As String
'Dim rs As Recordset
Set rs = OpenTable("GL")
Dim i As Long
Dim j As Long
'i = lngLastPostRow
i = lngFieldNameRow + 1
j = Sht.Range("ImportHeaderRow").Column
'Start at the beginning and go until you see a blank first cell in a row
While Sht.Cells(i, j).Value <> ""
'Check to see if the column should be posted
rs.AddNew
'Add the record entries
While j <= lngLastColumn
strCurrentField = Sht.Cells(lngFieldNameRow, j)
If strCurrentField <> "" Then
rsFinancialData(strCurrentField) = Sht.Cells(i, j).Value
End If
j = j + 1
Wend
rs("Computer") = getMachineName
rs("User") = getUserName
rs("DatePost") = Now
rs("Prgm") = Vbl.Range("FileName")
rs.Update
j = Sht.Range("ImportHeaderRow").Column ' Restate column position for next record
i = i + 1
Wend
rs.Close
Exit Sub
BadPost:
Msg = "Sorry you are not able to post your records at this time."
Msg = Msg & vbNewLine
Msg = Msg & "Would you like to email a copy of your parking lot record to yourself and finance? "
Msg = Msg & vbNewLine
Msg = Msg & vbNewLine
Msg = Msg & "Entering NO will erase all unposted entry. "
Ans2 = MsgBox(Msg, vbYesNoCancel)
'parklot.Unprotect ("john")
'If Ans2 = vbYes Then
' Vbl.Range("PostErrorFlag") = "1"
' UF_Email.Show
' parklot.Range("Parking_Lot").Clear
' ElseIf Ans2 = vbCancel Then
'' Cancel = True
' Exit Sub
' ElseIf Ans2 = vbNo Then
' parklot.Range("Parking_Lot").Clear
' ' Unload UF_Initial_Login
' UF_Intial_Login.Show
' End If
End Sub