Am I stupid or is it VB? [Recordsets] 
Author Message
 Am I stupid or is it VB? [Recordsets]

Here goes, hope this makes sense:

The user may search using two criteria, AONum & JobNum.  JobNum is
fine (because this is the primary key and there can only possibly be
one).  Anyway, when searching by AONum this may find more than one
JobNum with that same AONum, so the user can then select which job
from a datagrid, this works fine all the time there are > 0 records
found.  However, the program crashes if the JobNum is not found
because I have had to use this statement:

Data1.Recordset.MoveFirst
Data1.Recordset.MoveLast
If Data1.Recordset.RecordCount > 0 Then

Because without moving first and then last the recordcount always
comes back as 0, this is an annoying bug.  As you can see this will
work fine if the recordsets are actually > 0, but if the recordsets
are = 0 obviously it is not possible to move first then last, and this
crashes the program.  I tried using:

If rsJobs.AbsolutePosition > 0 Then

But it was proving even more difficult.  I hope someone can help, any
ideas are appreciated.

Thanks,

Lee.



Mon, 08 Dec 2003 00:03:59 GMT  
 Am I stupid or is it VB? [Recordsets]
Try:

If Not Data1.Recordset.EOF Then

If your search returns an empty record set, then
.EOF is True.

Terry Austin


Quote:
> Here goes, hope this makes sense:

> The user may search using two criteria, AONum & JobNum.  JobNum is
> fine (because this is the primary key and there can only possibly be
> one).  Anyway, when searching by AONum this may find more than one
> JobNum with that same AONum, so the user can then select which job
> from a datagrid, this works fine all the time there are > 0 records
> found.  However, the program crashes if the JobNum is not found
> because I have had to use this statement:

> Data1.Recordset.MoveFirst
> Data1.Recordset.MoveLast
> If Data1.Recordset.RecordCount > 0 Then

> Because without moving first and then last the recordcount always
> comes back as 0, this is an annoying bug.  As you can see this will
> work fine if the recordsets are actually > 0, but if the recordsets
> are = 0 obviously it is not possible to move first then last, and this
> crashes the program.  I tried using:

> If rsJobs.AbsolutePosition > 0 Then

> But it was proving even more difficult.  I hope someone can help, any
> ideas are appreciated.

> Thanks,

> Lee.



Mon, 08 Dec 2003 00:21:55 GMT  
 Am I stupid or is it VB? [Recordsets]
Instead of using

Data1.Recordset.MoveFirst
Data1.Recordset.MoveLast
If Data1.Recordset.RecordCount > 0 Then

try using

if not (rs.eof AND rs.bof) then
...

Good Luck



Mon, 08 Dec 2003 07:03:35 GMT  
 Am I stupid or is it VB? [Recordsets]


Quote:
>Because without moving first and then last the recordcount always
>comes back as 0, this is an annoying bug.  As you can see this will
>work fine if the recordsets are actually > 0, but if the recordsets
>are = 0 obviously it is not possible to move first then last, and this
>crashes the program.  I tried using:

>If rsJobs.AbsolutePosition > 0 Then

>But it was proving even more difficult.  I hope someone can help, any
>ideas are appreciated.

The easiest way to test whether or not there are records in the recordset
is:

        if rsJobs.BOF and rsJobs.EOF then

Both conditions will be true simultaneously if and only if there are no
records.
--
-A



Mon, 08 Dec 2003 07:50:48 GMT  
 Am I stupid or is it VB? [Recordsets]
I have a function I found in a tips & tricks section I use all the time for
this.  It gets copied into every project I do.  It's use should be obvious:

Public Function IsEmptyRecordset(rsInput As ADODB.Recordset) As Boolean
    IsEmptyRecordset = False
        If rsInput.EOF And rsInput.BOF Then IsEmptyRecordset = True
End Function

All you do is call the function and pass the recordset as a parameter.  It
returns a true or false value on whether the recordset has data or not,
without your having to do a test on it manually.  I use it right after
opening a recordset to see if I got anything back.  A great time-saver.
Hope you find it helpful.

Craig


Quote:


> >Because without moving first and then last the recordcount always
> >comes back as 0, this is an annoying bug.  As you can see this will
> >work fine if the recordsets are actually > 0, but if the recordsets
> >are = 0 obviously it is not possible to move first then last, and this
> >crashes the program.  I tried using:

> >If rsJobs.AbsolutePosition > 0 Then

> >But it was proving even more difficult.  I hope someone can help, any
> >ideas are appreciated.

> The easiest way to test whether or not there are records in the recordset
> is:

>     if rsJobs.BOF and rsJobs.EOF then

> Both conditions will be true simultaneously if and only if there are no
> records.
> --
> -A



Mon, 08 Dec 2003 22:29:09 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. I am learning VB.NET and am wondering....

2. Am I that stupid ?

3. Am I too stupid to program VBA?

4. How stupid am I being

5. How stupid am I being?

6. I am stupid but pleez help me

7. Am I Stupid ???

8. Am I Stupid ?...

9. Am I that stupid?

10. Using MSMAPI ocx: Am I stupid or what?

11. Is the dataCombo control stupid or am I?

12. MDI-problem-am i stupid or is it a bug -2 icons in menubar

 

 
Powered by phpBB® Forum Software