I am attempting to open an empty recordset from an Access 97 table. Then use the AddNew method of the recordset to add a new record. I'm getting a message saying the OLE DB provider doesn't support this operation or I've chosen the wrong CursorLock.
Code sample:
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSQL As String
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51; " & _
"Data Source=" & DBPath
cn.Open
rs.CursorLocation = adUseServer
rs.LockType = adLockOptimistic
strSQL = "SELECT * FROM [tblWorkRequests] WHERE 1=2"
Set rs = cn.Execute(strSQL)
rs.AddNew 'This is where it crashes
Does the Access OLE DB not allow you to do this or am I simply doing it incorrectly? The reason I was trying to add the record this way instead of just running a SQL INSERT statement is because there is an autonumber field for the record ID and I want to grab the ID number after it has been generated. If there's another way to do that please let me know.
Thanks,
Brett
Code sample:
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSQL As String
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51; " & _
"Data Source=" & DBPath
cn.Open
rs.CursorLocation = adUseServer
rs.LockType = adLockOptimistic
strSQL = "SELECT * FROM [tblWorkRequests] WHERE 1=2"
Set rs = cn.Execute(strSQL)
rs.AddNew 'This is where it crashes
Does the Access OLE DB not allow you to do this or am I simply doing it incorrectly? The reason I was trying to add the record this way instead of just running a SQL INSERT statement is because there is an autonumber field for the record ID and I want to grab the ID number after it has been generated. If there's another way to do that please let me know.
Thanks,
Brett