B
Brian
Hi!
I have a recordset that (after it is generated) needs to have several record
deleted. I have tried this using ADO but when i find the record to be
deleted and try to delete it, i get an error saying that the data is read
only. My code follows:
---------------------------------
Sub Form_Load()
Dim zipStore As String
On Error GoTo Err_Load
Dim rec As Boolean
Set rst = New ADODB.Recordset
Debug.Print "LOAD " & strsearch
rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenKeyset
rst.LockType = adLockOptimistic
Debug.Print "hello"
rst.Open strsearch, Options:=adCmdText
Set Me.Recordset = rst
If Box = True Then 'Box is global varible in another module
Do Until rst.EOF
If Me!CR = "C" Then
zipStore = Me!ZIPCODE
Do Until rst.EOF
If ((Me!ZIPCODE = zipStore) And (Me!CR = "C")) Or
((Me!ZIPCODE = zipStore) And (Me!CR = "B")) Then
rst.Delete
End If
rst.MoveNext
Loop
End If
rst.MoveNext
Loop
End If
Exit_Load:
Exit Sub
Err_Load:
MsgBox Err.Description
Resume Exit_Load
End Sub
-----------------------------------
In all examples where the records are editable, there is a constant query
statement after rst.Open, such as "Select * ftom tblTimeCard" or something
simular. In my case, I cannot do this, because my query changes based on
options i have on a form.
Maybe i am approaching this in the totally wrong way, but can anyone tell me
how to make the recordset records deletable?
Thanks for any help!
Brian Boykin
I have a recordset that (after it is generated) needs to have several record
deleted. I have tried this using ADO but when i find the record to be
deleted and try to delete it, i get an error saying that the data is read
only. My code follows:
---------------------------------
Sub Form_Load()
Dim zipStore As String
On Error GoTo Err_Load
Dim rec As Boolean
Set rst = New ADODB.Recordset
Debug.Print "LOAD " & strsearch
rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenKeyset
rst.LockType = adLockOptimistic
Debug.Print "hello"
rst.Open strsearch, Options:=adCmdText
Set Me.Recordset = rst
If Box = True Then 'Box is global varible in another module
Do Until rst.EOF
If Me!CR = "C" Then
zipStore = Me!ZIPCODE
Do Until rst.EOF
If ((Me!ZIPCODE = zipStore) And (Me!CR = "C")) Or
((Me!ZIPCODE = zipStore) And (Me!CR = "B")) Then
rst.Delete
End If
rst.MoveNext
Loop
End If
rst.MoveNext
Loop
End If
Exit_Load:
Exit Sub
Err_Load:
MsgBox Err.Description
Resume Exit_Load
End Sub
-----------------------------------
In all examples where the records are editable, there is a constant query
statement after rst.Open, such as "Select * ftom tblTimeCard" or something
simular. In my case, I cannot do this, because my query changes based on
options i have on a form.
Maybe i am approaching this in the totally wrong way, but can anyone tell me
how to make the recordset records deletable?
Thanks for any help!
Brian Boykin