I am working with a recordset problem in Access 2010. Below is the code I have so far and I get an error where commented. The error I get is: Run-time error '-2147467259(80004005)':Unrecognized database format 'C:\Users\fc\desktop\MyRecordsetDB.accdb'.
I have the following References active:
Visual Basic for Applications
Microsoft Access 14.0 Object Library
OLE Automation
Microsoft ActiveX Data Objects 2.6 Library
The database was created using Access 2010.
I have not been able to check any of the rest of the code so I don't know if there are any other errors.
Code:
Private Sub Form_Load()
Dim cnn1 As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strCnn As String
'create string var to hold new information
Dim strID As String, strLot As String, strAM As String, strPM As String
'variable to hold path to current db name
Dim strPath As String
strPath = Application.CurrentProject.Path & "" & Application.CurrentProject.Name
Dim mydb As String
mydb = strPath
'MsgBox strPath for testing purposes only but shows correct path
' Open a connection.
Set cnn1 = New ADODB.Connection
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mydb
/////////////Error occurs on next line/////////////////////////////
cnn1.Open strCnn
' Open contact table.
Set rs = New ADODB.Recordset
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
rs.Open Source:="Select * from tblTest"
'get the new record data
'Use inputbox to get info for new record
strID = Val(InputBox("Enter ID", "Manager ID Number"))
strLot = InputBox("Enter lot number", "Lot Number")
strAM = InputBox("Does this employee work the AM shift? vbnewLine Enter Yes or No", "Shift Assignment")
strPM = InputBox("Does this employee work the PM shift? vbnewLine Enter Yes or N0", "Shift Assignment")
rs.AddNew
rs!mgrID = strID
rs!mgrID = strLot
rs!mgrID = strAM 'update the Y/N field in the recordset to Yes or No
rs!mgrID = strPM 'update the Y/N field in the recordset to Yes or No
' Show the newly added data.
MsgBox "New manager ID: " & rs!mgrID & " has been successfully added"
'close connections
rs.Close
cnn1.Close
End Sub
Thank you for your help