Can anyone help - I cannot seem to get the following ADO recordset to allow updates. I keep getting a run time error stating that the recordset does not allow updating. The recordset opens fine and I have tried changing the cursor types and lock types to no avail
The code is as follows:
The query is just a straight select statement with parameters from a table that allows updating
Regards
Jon
The code is as follows:
Code:
Private Sub cmdUpdateDB_Click()
Dim rs As ADODB.Recordset
Dim cm As ADODB.Command
Dim intLneNo As Integer
Dim sglDia As Single
Dim strPID As String
strPID = Me.lstPID
sglDia = Me.cboDiaPk
intLneNo = Me.cboPipLop
Set cm = New ADODB.Command
With cm
.ActiveConnection = CurrentProject.Connection
.CommandText = "AdoQryUpdt_PID_PIP"
.CommandType = adCmdTable
.Parameters.Refresh
.Parameters("[Param1]") = strPID
.Parameters("[Param2]") = intLneNo
.Parameters("[Param3]") = sglDia
End With
Set rs = New ADODB.Recordset
With rs
.CursorType = adOpenKeyset
.LockType = adLockPessimistic
.CursorLocation = adUseServer
End With
Set rs = cm.Execute
If rs.EOF = True Or rs.BOF = True Then
rs.AddNew
rs!fldPIDPk = strPID
rs!fldLneNoPK = intLneNo
rs!fldDiaPk = sglDia
rs.Save
Else
MsgBox "This record exists!", vbOKOnly, "Data Clash"
End If
rs.Close
Set rs = Nothing
Set cm = Nothing
Set cm = Nothing
End Sub
Regards
Jon