[Solved] Run-time Error regarding BOF or EOF
When I open the "New Customer Maintenance" form (where I could fill out the fields so that they get updated on the datagrid) I get this errror:
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
Here's the code:
VB Code:
Private Sub LoadData()
Dim psql As String
Set cnn = New ADODB.Connection
cnn.Mode = adModeReadWrite
cnn.Open ("INVENTORY")
Set rec = New ADODB.Recordset
rec.CursorType = adOpenKeyset
rec.LockType = adLockOptimistic
psql = "select * from tblCustomerInformation "
psql = psql + " where CustNo = " + Trim(Str(Id))
rec.Open psql, cnn, , , 1
*Text2.Text = IIf(IsNull(rec!Fname), "", rec!Fname)
Text1.Text = IIf(IsNull(rec!Lname), "", rec!Lname)
Text5.Text = IIf(IsNull(rec!ContactNo), "", rec!ContactNo)
Text8.Text = IIf(IsNull(rec!EmailAdd), "", rec!EmailAdd)
Text14.Text = IIf(IsNull(rec!Birthday), "", rec!Birthday)
'Text9.Text = IIf(IsNull(rec!Gender), "", rec!Gender)
Text9.Text = IIf(IsNull(rec!Address), "", rec!Address)
Text13.Text = IIf(IsNull(rec!Comment), "", rec!Comment)
End Sub
The line with the asterisk is highlighted when debugged.
Re: Run-time Error regarding BOF or EOF
VB Code:
rec.Open psql, cnn, , , 1
[color=red]If [color=red]Not[/COLOR] rec.[color=red]EOF[/COLOR] Then[/COLOR]
*Text2.Text = IIf(IsNull(rec!Fname), "", rec!Fname)
Text1.Text = IIf(IsNull(rec!Lname), "", rec!Lname)
Text5.Text = IIf(IsNull(rec!ContactNo), "", rec!ContactNo)
Text8.Text = IIf(IsNull(rec!EmailAdd), "", rec!EmailAdd)
Text14.Text = IIf(IsNull(rec!Birthday), "", rec!Birthday)
'Text9.Text = IIf(IsNull(rec!Gender), "", rec!Gender)
Text9.Text = IIf(IsNull(rec!Address), "", rec!Address)
Text13.Text = IIf(IsNull(rec!Comment), "", rec!Comment)
[COLOR=Red]End If[/COLOR]
Re: Run-time Error regarding BOF or EOF
It worked. I mean I no longer get the error. But what's the real problem with it? I mean am I missing a record or is there a mismatch on the record name?
Thanks a bunch. ;)
Re: Run-time Error regarding BOF or EOF
the problem is there is no records to be return by the sql statement
try searching a record that does not exist you will have the same error message
Quote:
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
use a142 suggestion
Re: Run-time Error regarding BOF or EOF
on a sidenote, you can also just do:
VB Code:
Text2.Text = rec!Fname & ""
Text1.Text = rec!Lname & ""
'etc.
instead of all those IsNull checks
Re: Run-time Error regarding BOF or EOF
Anyway, I figured out the problem. Thanks for the help!