Re: ADO Record Count



Exactly, this was the case that hit me. I could have fixed it by using a
rs.movefirst in this case, but what if no records were returned and I tried
moving first? Yup, going to bomb out on me.

Main factor seems to be the a combination of cursor type and cursor location
that can cause it to trip up. I'll continue to play it safe by checking BOF
and EOF
to see if I have records.

"argusy" <argusy@xxxxxxxxxxxxxxx> wrote in message
news:42870218.2000904@xxxxxxxxxxxxxxxxxx
> Your statement
> "If there are records, they both should be false. If no records, they both
> should be true."
>
> Basically true, but ...
> if there are no records, **testing** for .eof and .bof will show they're
true
> If there are records, AND THE CURSOR IS ON A RECORD, **testing** both will
show
> they're false.
> if the cursor is at .eof or .bof, then **testing** them will show ONE IS
TRUE,
> AND THE OTHER FALSE, depending which end you're at.
> Don't EVER think they're both false because a recordset has records - it
depends
> on the cursor position.
>
> recordset.movefirst
> If recordset.eof then ' no records
>
> or
>
> recordset.movelast
> if recordset.bof then ' no records
>
> will ALWAYS define a recordset that doesn't have records
>
> Veign's right.
> But just to make sure, I always include a .movefirst prior to testing for
the
> end-of-file in a just opened ADO recordset - it might be anywhere
>
> Argusy
>
> Nobody wrote:
> > Nope, not 100% reliable from my experience. I've seen that fail before
had
> > the code
> > try to process records that aren't there. I just had to fix someone's
> > code last week because they were only checking rs.EOF and the app
> > was bombing at times. Checking EOF and BOF fixed it.
> >
> > If there are records, they both should be false. If no records, they
both
> > should be true.
> > So just checking one of them to see if it is true should work, but as
stated
> > I've seen
> > cases where it didn't
> >
> > "Veign" <NOSPAMinveign@xxxxxxxxx> wrote in message
> > news:%23qaabNwVFHA.3704@xxxxxxxxxxxxxxxxxxxxxxx
> >
> >>You only need to check for EOF for records returned..
> >>
> >>Like:
> >>IF Not rs.EOF Then
> >> 'We got records to process
> >>End If
> >>
> >>--
> >>Chris Hanscom - Microsoft MVP (VB)
> >>Veign's Resource Center
> >>http://www.veign.com/vrc_main.asp
> >>--
> >>Read. Decide. Sign the petition to Microsoft.
> >>http://classicvb.org/petition/
> >>
> >>
> >>"Nobody" <trinity@xxxxxxxxxx> wrote in message
> >>news:%23RcBKWvVFHA.3840@xxxxxxxxxxxxxxxxxxxxxxx
> >>
> >>>That isn't the best way (my opinion) to check to see if you actually
> >>
> > have
> >
> >>>records. I do something like this:
> >>>
> >>>IF Not ((rs.BOF = True) And (rs.EOF = True)) Then
> >>> 'We got records to process
> >>>End If
> >>>
> >>>
> >>>"Dan" <danno492_NOSPAM@xxxxxxxxxxx> wrote in message
> >>>news:O%236hFMvVFHA.584@xxxxxxxxxxxxxxxxxxxxxxx
> >>>
> >>>>Hi all,
> >>>>I have a problem trying to get the record count to 0
> >>>>below is the code I am using.
> >>>>If I send an incorrect password, I should then get a record count of
> >>>
> > 0.
> >
> >>>>However, it is always giving me a recordcount of > 0, regardless of
> >>>
> > what
> >
> >>>it
> >>>
> >>>>is sent.
> >>>>Any ideas?
> >>>>
> >>>>Function IsValidLogon(strUserName As String, strPassword As String) As
> >>>>Boolean
> >>>>'On Error Resume Next
> >>>>Dim cnnADS As ADODB.Connection
> >>>>Dim rs As New ADODB.Recordset
> >>>>Dim strRS As String
> >>>>
> >>>> IsValidLogon = False
> >>>>
> >>>> Set cnnADS = New ADODB.Connection
> >>>>
> >>>> cnnADS.ConnectionString = "Provider=Advantage.OLEDB.1; Data Source="
> >>>
> > &
> >
> >>>>GetDataPath & ";" & _
> >>>> "User ID='AdsSys';Password='';"
> >>>>
> >>>> cnnADS.Open
> >>>>
> >>>> strRS = "SELECT USERNAME, PASSWORD FROM storpers " & _
> >>>> "where USERNAME='" & strUserName & "' AND PASSWORD='" &
> >>>
> > strPassword
> >
> >>&
> >>
> >>>>"'"
> >>>> '"where PASSWORD='" & strPassword & "'"
> >>>>
> >>>> rs.Open strRS, cnnADS, adOpenKeyset, adLockReadOnly
> >>>>
> >>>> With rs
> >>>> If .RecordCount > 0 Then
> >>>>
> >>>> If !UserName = strUserName Then
> >>>>
> >>>> If !Password = strPassword Then
> >>>>
> >>>> IsValidLogon = True
> >>>>
> >>>> Else
> >>>>
> >>>> IsValidLogon = False
> >>>>
> >>>> End If
> >>>>
> >>>> End If
> >>>>
> >>>> Else
> >>>> IsValidLogon = False
> >>>> End If
> >>>>
> >>>> .Close
> >>>>
> >>>> End With
> >>>>
> >>>> Set rs = Nothing
> >>>> cnnADS.Close
> >>>> Set cnnADS = Nothing
> >>>>End Function
> >>>>
> >>>>
> >>>
> >>>
> >>
> >
> >
>


.



Relevant Pages

  • RE: Find and Find Next
    ... In a command button click event have the following: ... Do Until .EOF ... certain criteria and the cursor goes to that record. ...
    (microsoft.public.access.formscoding)
  • Re: Returning Null value instead of contents of field
    ... Good call on the cursor type change I misunderstood what was happening. ... The test for EOF and BOF is to make sure the open statement had returned at ... empty recordset. ...
    (microsoft.public.data.ado)
  • Re: EM_SCROLLCARET problem
    ... >I'm using RichEdit to display Div. ... >It does put the cursor at the eof ok, but the eof is not alwise at the ... >How can I fix this that the eof is at the bottom of RE? ... Try forcing the cursor to the top of the file before using ...
    (alt.comp.lang.borland-delphi)
  • Re: Crazy Readonly
    ... > EOF() in the bound alias. ... Or maybe the cursor got lost entirely. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: ADO Record Count
    ... Show me a case where just checking EOF only would not produce the expected ... Sign the petition to Microsoft. ... > try to process records that aren't there. ...
    (microsoft.public.vb.database.ado)