|
-
Feb 7th, 2007, 10:26 AM
#1
Thread Starter
Lively Member
.eof or .bof is true, or current recordset has been deleted. requested operation requ
when my table is empty i always encounter this error what will do.
-
Feb 7th, 2007, 10:30 AM
#2
Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ
That do you want the application to do?
When I open a recordset before I do anything with it I check for .BOF and .EOF like this:
VB Code:
rs.Open strSQL
if Not rs.BOF and Not rs.EOF then
'Do something with the result set
else
'Something to do if nothing is there
end if
if not rs is Nothing then
if rs.State then rs.Close
set rs = Nothing
end if
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Feb 7th, 2007, 10:35 AM
#3
Thread Starter
Lively Member
Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ
i try your code but still have error... here's my code
VB Code:
Private Sub cmdSave_Click()
If CheckTextBox(txtDepTitle, "Invalid 'DEPARTMENT Title' value. This field is required, please enter a value.") = False Then
StartTxt txtDepTitle
Else
With tbDepartment
.MoveFirst
.Find "DepartmentName = '" & txtDepTitle & "'"
If .EOF = True Then
.AddNew
.Fields(0) = txtDepTitle
.Update
.Requery
End If
End With
ans = MsgBox("New Deparment entry successfully saved to the record." & vbNewLine & "Do You Want To Add Another Record?", vbYesNo, "Titus School Of Multimedia")
If ans = vbNo Then
Unload Me
End If
End If
End Sub
-
Feb 7th, 2007, 10:58 AM
#4
Member
Re: .eof or .bof is true, or current recordset has been deleted. requested operation
from ur code, try this one :
Code:
With tbDepartment '// Assumming this is an open recordset
If .EOF or .BOF Then
Msgbox "No Record(s)",64,App.Title
.Close
Exit Sub
End If
.MoveFirst
.Find "DepartmentName = '" & txtDepTitle & "'"
If .EOF = True Then
End If
End With
-
Feb 7th, 2007, 11:01 AM
#5
Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ
If there are no records then the .MoveFirst will cause the error. You need to test for BOF/EOF before you try and move in a recordset. Also when the recordset is first opened there is no need to issued the .MoveFirst method you are already at the first record.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Feb 7th, 2007, 11:02 AM
#6
Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ
 Originally Posted by mheiy
VB Code:
Private Sub cmdSave_Click()
If CheckTextBox(txtDepTitle, "Invalid 'DEPARTMENT Title' value. This field is required, please enter a value.") = False Then
StartTxt txtDepTitle
Else
With tbDepartment
.MoveFirst
.Find "DepartmentName = '" & txtDepTitle & "'"
If .EOF = True Then
.AddNew
.Fields(0) = txtDepTitle
.Update
.Requery
End If
End With
ans = MsgBox("New Deparment entry successfully saved to the record." & vbNewLine & "Do You Want To Add Another Record?", vbYesNo, "Titus School Of Multimedia")
If ans = vbNo Then
Unload Me
End If
End If
End Sub
 Originally Posted by mheiy
when my table is empty i always encounter this error what will do.
Why are you doing a .MoveFirst on an empty table? Why are you trying to Search an empty table?
Either and both of those will result in an EOF error.
-
Feb 7th, 2007, 11:39 AM
#7
Thread Starter
Lively Member
Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ
what if there's a record already...
-
Feb 7th, 2007, 11:43 AM
#8
Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ
 Originally Posted by mheiy
what if there's a record already...
Then, if what you said in your first post
 Originally Posted by mheiy
when my table is empty i always encounter this error what will do.
is true, you shouldn't get the error.
-
Feb 7th, 2007, 11:49 AM
#9
Thread Starter
Lively Member
Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ
ok at first my table is empty then im going to add new one... and add again other one
-
Feb 7th, 2007, 12:13 PM
#10
Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ
So, do you continue to get the .EOF/.BOF error when the table is not empty?
-
Feb 7th, 2007, 12:22 PM
#11
Thread Starter
Lively Member
Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ
you dont understand me...
what im trying to say is when my table is empty i got an error.. then you say that why do i need to .Movefirst and search... i need the .movefirst when my table is not empty.. got it
-
Feb 7th, 2007, 12:30 PM
#12
Re: .eof or .bof is true, or current recordset has been deleted. requested operation
As mentioned several times, you can only do a MoveFirst or Find if there are records.. check EOF/BOF (as shown already - Just a noob's example is good) to see if there are records, and only do the .MoveFirst/Find if there are.
-
Feb 7th, 2007, 12:32 PM
#13
Member
Re: .eof or .bof is true, or current recordset has been deleted. requested operation
Code:
Option Explicit
Private c As ADODB.Connection
Private r As ADODB.Recordset
Private Function AddNewRec(IdentifyValue As String) As Boolean
On Error Resume Next
'No need for .MoveFirst or Looping throught recordset _
if u just want to Add or Update record !!!
With r
.Open "select [Fields] from [Table] where [FieldIdentify]='" & _
IdentifyValue & "';", c, adOpenDynamic, adLockOptimistic
If (.EOF Or .BOF) Then .AddNew '/. No Record(s) that match _
Criteria or table is Empty - AddNew
.Fields(0).Value = "Some Value"
.Update '/. if found match record from where clause _
perform - Update
.Close
End With
AddNewRec = True
If (Err <> 0) Then
AddNewRec = False
On Error GoTo 0
Err.Clear
End If
End Function
-
Feb 7th, 2007, 12:35 PM
#14
Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ
Let's start with the code you use to open the record set. Can we see what you are doing? As alrready said if the recordset is empty and you do a .MoveFirst then you get an error. If the recordset is empty and you do a .Seach then you get an error. You can not perform either if the recordset is empty. So before you do either of them check for BOF/EOF. It either condition is true then you have and empty recordset and don't perform a .MoveFirst or .Search. just go to the add new if that is what you wnat to do.
In trruth you should start to learn SQL language to reteive the data you wnat not just open a table and look for stuff in it.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Feb 7th, 2007, 01:13 PM
#15
Thread Starter
Lively Member
Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ
how can i know if there's an existing record already
-
Feb 7th, 2007, 01:22 PM
#16
Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ
When you open the recordset you perform this code (as I showed you in post number 2):
VB Code:
if Not tbDepartment.BOF and Not tbDepartment.EOF then
Do you stuff here
else
MsgBox "No Records returned NOTHING TO SEARCH FOR HERE!"
end if
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Feb 7th, 2007, 01:30 PM
#17
Frenzied Member
Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ
 Originally Posted by GaryMazzone
When you open the recordset you perform this code (as I showed you in post number 2):
VB Code:
if Not tbDepartment.BOF and Not tbDepartment.EOF then
Do you stuff here
else
MsgBox "No Records returned NOTHING TO SEARCH FOR HERE!"
end if
Better yet
 Originally Posted by GaryMazzone
start to learn SQL language
Then all you would have to do is a SELECT COUNT(*) FROM tablename, and badda bing, you would know how many records are in your table.
Beantown Boy
Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
-
Feb 7th, 2007, 01:58 PM
#18
Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ
And badda bing, that required two trips to the database.....
-tg
-
Feb 7th, 2007, 02:51 PM
#19
Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ
 Originally Posted by techgnome
And badda bing, that required two trips to the database.....
-tg
Not if all he wanted was a count of the records.
-
Feb 8th, 2007, 11:25 AM
#20
Thread Starter
Lively Member
Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ
i've alredy your code and its running now but when i need to add another record its not adding. what will i do
-
Feb 8th, 2007, 11:36 AM
#21
Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ
Whose code are you running?
What happens when you try to add another record?
-
Feb 8th, 2007, 11:42 AM
#22
Thread Starter
Lively Member
Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ
VB Code:
if Not tbDepartment.BOF and Not tbDepartment.EOF then
Do you stuff here
else
MsgBox "No Records returned NOTHING TO SEARCH FOR HERE!"
end if
the msgbox "no records forund" is always shown
-
Feb 8th, 2007, 12:22 PM
#23
Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ
The code I should you will not add a new record to the table. It just shows what to do if no records are returned from the table.
What is the code you are using to add a new record? (I really hope it's not .AddNew and .Update I still think the SQL statements are better to learn).
Sometimes the Programmer
Sometimes the DBA
Mazz1
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
|