|
-
Feb 7th, 2007, 05:46 AM
#1
Thread Starter
Lively Member
current recordset does not support scrolling backward
im going to delete a record but i encounter an error of current recordset does not support scrolling backward..
here's my code
Code:
Private Sub cmdDelete_Click()
With tbDepartment
ans = MsgBox("Are you sure you want to delete this record?", vbYesNo + vbQuestion, "Wait")
If ans = vbYes Then
.Find "DepartmentName = '" & txtDepTitle.Text & "'"
If .EOF = True Then
MsgBox "Huh?"
Else
.Delete
.Requery
txtDepTitle = ""
End If
Else
Refresh
End If
End With
End Sub
Private Sub cmdGetDepartment_Click()
PickDepartment.Show
PickDepartment.cmdSelect.Visible = False
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub Form_Load()
tbdepartment.open "Select * from tbdepartment", cn. adopendynamic, adloackoptimistic
end sub
-
Feb 7th, 2007, 05:55 AM
#2
Re: current recordset does not support scrolling backward
Is this "adloackoptimistic" really in your code or just a pasting error?
-
Feb 7th, 2007, 06:02 AM
#3
Re: current recordset does not support scrolling backward
I think it's adLockOptimistic.
-
Feb 7th, 2007, 07:02 AM
#4
Re: current recordset does not support scrolling backward
also i believe should be comma after cn, not period
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Feb 7th, 2007, 07:40 AM
#5
Thread Starter
Lively Member
Re: current recordset does not support scrolling backward
Private Sub cmdDelete_Click()
With tbDepartment
ans = MsgBox("Are you sure you want to delete this record?", vbYesNo + vbQuestion, "Wait")
If ans = vbYes Then
.Find "DepartmentName = '" & txtDepTitle.Text & "'"
If .EOF = True Then
MsgBox "Huh?"
Else
.Delete
.Requery
txtDepTitle = ""
End If
Else
Refresh
End If
End With
End Sub
Private Sub cmdGetDepartment_Click()
PickDepartment.Show
PickDepartment.cmdSelect.Visible = False
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub Form_Load()
Set tbDepartment = Nothing
dept = "Select * from tbdepartment where DepartmentName like '" & txtDepTitle.Text & "'"
tbDepartment.Open dept, cn, adOpenDynamic, adLockOptimistic
End Sub
-
Feb 7th, 2007, 09:09 AM
#6
Re: current recordset does not support scrolling backward
Try this
VB Code:
rivate Sub cmdDelete_Click()
With tbDepartment
ans = MsgBox("Are you sure you want to delete this record?", vbYesNo + vbQuestion, "Wait")
If ans = vbYes Then
.Find "DepartmentName = '" & txtDepTitle.Text & "'"
If .EOF = True Then
MsgBox "Huh?"
Else
.Delete
[B] ' .Requery[/B] 'Comment this line and run
txtDepTitle = ""
End If
Else
Refresh
End If
End With
End Sub
Please mark you thread resolved using the Thread Tools as shown
-
Feb 7th, 2007, 09:23 AM
#7
Thread Starter
Lively Member
Re: current recordset does not support scrolling backward
it was running now but it always show the msgbox. and the .EOF is always true
VB Code:
Private Sub cmdDelete_Click()
'Set tbDepartment = Nothing
'dept = "Select * from tbdepartment where DepartmentName like '" & txtDepTitle.Text & "'"
'tbDepartment.Open dept, cn, adOpenDynamic, adLockOptimistic
tbDepartment.Open "Select * from tbdepartment", cn, adOpenDynamic, adLockOptimistic
With tbDepartment
ans = MsgBox("Are you sure you want to delete this record?", vbYesNo + vbQuestion, "Wait")
If ans = vbYes Then
.Find "DepartmentName = '" & txtDepTitle.Text & "'"
If .EOF = True Then
MsgBox "Huh?"
Else
.Delete
' .Requery
txtDepTitle = ""
End If
Else
Refresh
End If
End With
End Sub
-
Feb 7th, 2007, 09:33 AM
#8
Re: current recordset does not support scrolling backward
I think you can try this method
VB Code:
Private Sub cmdDelete_Click()
'Set tbDepartment = Nothing
'Dim tbDepartment As New ADODB.Recordset
'dept = "Select * from tbdepartment where DepartmentName like '" & txtDepTitle.Text & "'"
'tbDepartment.Open dept, cn, adOpenDynamic, adLockOptimistic
If MsgBox("Are you sure you want to delete this record?", vbYesNo + vbQuestion, "Wait") = vbYes Then
tbDepartment.Open "Select * from tbdepartment where DepartmentName='" & txtDepTitle.Text & "'", cn, adOpenDynamic, adLockOptimistic
If tbDepartment.EOF = False Then
tbDepartment.Delete adAffectCurrent
Else
MsgBox "Huh?"
txtDepTitle = ""
End If
End If
End Sub
Please mark you thread resolved using the Thread Tools as shown
-
Feb 7th, 2007, 09:35 AM
#9
Thread Starter
Lively Member
Re: current recordset does not support scrolling backward
whats the use of adaffectcurrent
-
Feb 7th, 2007, 09:40 AM
#10
Thread Starter
Lively Member
Re: current recordset does not support scrolling backward
still not working and have the same error
-
Feb 7th, 2007, 09:44 AM
#11
Thread Starter
Lively Member
Re: current recordset does not support scrolling backward
it was running now thank you
-
Feb 7th, 2007, 09:44 AM
#12
Re: current recordset does not support scrolling backward
Try this also
VB Code:
Private Sub cmdDelete_Click()
'Set tbDepartment = Nothing
'Dim tbDepartment As New ADODB.Recordset
'dept = "Select * from tbdepartment where DepartmentName like '" & txtDepTitle.Text & "'"
'tbDepartment.Open dept, cn, adOpenDynamic, adLockOptimistic
If MsgBox("Are you sure you want to delete this record?", vbYesNo + vbQuestion, "Wait") = vbYes Then
'tbDepartment.Open "Select * from tbdepartment where DepartmentName='" & txtDepTitle.Text & "'", cn, adOpenDynamic, adLockOptimistic
cn.Execute ("Delete * from tbdepartment where DepartmentName='" & txtDepTitle.Text & "'")
' If tbDepartment.EOF = False Then
' tbDepartment.Delete adAffectCurrent
' Else
' MsgBox "Huh?"
' txtDepTitle = ""
' End If
End If
End Sub
Please mark you thread resolved using the Thread Tools as shown
-
Feb 7th, 2007, 09:46 AM
#13
Re: current recordset does not support scrolling backward
Please mark you thread resolved using the Thread Tools as shown
-
Feb 7th, 2007, 09:49 AM
#14
Thread Starter
Lively Member
Re: current recordset does not support scrolling backward
how about this one.... when i'm adding a new data and my table is empty i always encounter the .eof or .bof is closed or deleted. how can i avoid this even if my table is empty
-
Feb 7th, 2007, 09:52 AM
#15
Re: current recordset does not support scrolling backward
VB Code:
tbDepartment.Open "Select * from tbdepartment where 1<>1", cn, adOpenDynamic, adLockOptimistic
tbDepartment.addnew
'Do your additions
tbDepartment.update
Please mark you thread resolved using the Thread Tools as shown
-
Feb 7th, 2007, 09:56 AM
#16
Thread Starter
Lively Member
Re: current recordset does not support scrolling backward
in all my tables when i' going to add i have to this code same with other tables
VB Code:
tbDepartment.Open "Select * from tbdepartment where 1<>1", cn, adOpenDynamic, adLockOptimistic
tbDepartment.addnew
'Do your additions
tbDepartment.update
-
Feb 7th, 2007, 09:59 AM
#17
Thread Starter
Lively Member
Re: current recordset does not support scrolling backward
i still have the same error either .eof or .bof is true, or current recordset has been deleted. requested operation requires a record... this the error i always got when that table is empty
-
Feb 7th, 2007, 02:51 PM
#18
Re: current recordset does not support scrolling backward
The Find method requires you to initialize the recordset with a .Movexxxxx call. Either MoveFirst or MoveLast depending on the search direction you will be performing.
You can pass the argument of adSearchForward or adSearchBackwards. Depending on the direction of the search, if no matching record is found then the rs will be positioned at either the BOF or EOF.
I personally dont like using Find as its just creates more work/code to use when you can just call the delete action in a sql statement call. The call will still be made to the db with the Find plus you will have to execute the delete too so by passing the "DELETE Table1 FROM Table1 WHERE SomeField = 'Something'" is preferred.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|