I have followed several links here and elsewhere and just can't figure out what I am doing wrong!
I select items from a listbox display and then wish to update (2 lines for my testing).
The first iteration appears to go through all steps when in debug mode BUT does not actually update the database. The second iteration FAILS at the update command and goes to ErrHandler:. ID is a unique record ID in Access and Trans_Comment is a valid field name. The records have not been updated or deleted
The error is
[TABLE="width: 282"]
<tbody>[TR]
[TD="width: 282"]3021:Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.[/TD]
[/TR]
</tbody>[/TABLE]
I have had something similar working previously then made changes.
any help appreciated
I select items from a listbox display and then wish to update (2 lines for my testing).
The first iteration appears to go through all steps when in debug mode BUT does not actually update the database. The second iteration FAILS at the update command and goes to ErrHandler:. ID is a unique record ID in Access and Trans_Comment is a valid field name. The records have not been updated or deleted
The error is
[TABLE="width: 282"]
<tbody>[TR]
[TD="width: 282"]3021:Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.[/TD]
[/TR]
</tbody>[/TABLE]
I have had something similar working previously then made changes.
Code:
Sub Category_update()
Dim int1 As Integer, Item_ID As Integer
Dim str0 As String, str1 As String, str2 As String, str3 As String, str4 As String, mycomment As String
On Error GoTo ErrHandler
str1 = DBtable
Connect2Access_Init
For int1 = 1 To ListBox2.ListCount - 1
If ListBox2.Selected(int1) = True Then
str1 = ListBox2.List(int1, 4)
MsgBox ("List Item ID = " & str1 & " is selected to update")
mycomment = "Utilities Energy" ' hard coded for tesTing
Set rs = New ADODB.Recordset
mycmd = "SELECT * FROM " + DBtable + " WHERE ID = " + str1 + ";"
With rs
.Open Source:=mycmd, ActiveConnection:=cn, LockType:=adLockOptimistic
.Fields("Trans_Comment") = mycomment
.Update
.Close
End With
End If
Next int1
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
Exit Sub
ErrHandler:
Error_Handler ("Category_update")
End Sub
any help appreciated
Last edited: