Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2002
    Location
    Inland Northwest(US)
    Posts
    19

    Unanswered: RecordCount issues

    When I try to use the RecordCount proerty it comes up with a -1 instead of the number of records in my recordset. Am I opening the recordset incorrectly?

    Dim Lookup_Table As New ADODB.Recordset
    Dim DataBaseName As ADODB.Connection
    Set DataBaseName = CurrentProject.Connection
    Lookup_Table.Open "User_List", DataBaseName, adOpenForwardOnly, _ adLockOptimistic, adCmdTable

    If Lookup_Table.RecordCount > 0 Then
    'blah blah blah
    End If
    Lookup_Table.Close

    Thanks
    Laeskia

  2. #2
    Join Date
    Oct 2002
    Location
    Rochester, NY
    Posts
    84
    You should be able to determine if the recordset is opening properly by examining the BOF and EOF properties in a local window. Set a breakpoint on the line where you open the table and step into the next line. You should see the Lookup_Table object in the local window. Expand it and check to make sure that neither BOF or EOF are TRUE. BOF and EOF stand for Begining and End of File, respectively. If you have records in the table and you are able to connect to the database, neither should be TRUE and the recordcount property should be the total number of records in the table.

    One other note:
    You should try declaring the recordset object and instantiate it on two separate lines of code, eg.

    Dim Lookup_Table as ADODB.Recordset

    ...

    Set Lookup_table = New ADODB.Recordset
    Regards,
    Terry

  3. #3
    Join Date
    Oct 2002
    Location
    Inland Northwest(US)
    Posts
    19
    I am a student so I am forever asking why. Do mind if I ask why this is a better declaration for a recordset? Is it just better form, better programming etiquette, does it affect code? I don't intend to be rude by any means, I'm just trying to learn.

    Thanks,
    Laeskia

    PS. I figured out what was going on with my code. I am eternally grateful for you input
    Last edited by Laeskia; 11-07-02 at 16:20.

  4. #4
    Join Date
    Oct 2002
    Location
    Rochester, NY
    Posts
    84
    Originally posted by Laeskia
    I am a student so I am forever asking why. Do mind if I ask why this is a better declaration for a recordset? Is it just better form, better programming etiquette, does it affect code? I don't intend to be rude by any means, I'm just trying to learn.

    Thanks,
    Laeskia
    No problem at all.

    Etiquette might be a part of it, but I have seen cases where the code should work, but it just won't until you use the form where the declare and instantiation occur as separate lines. I haven't seen it often enough that I can show a definite pattern, though. I do know that the form I recommended does eliminate most problems from opening recordsets (in the event they might occur.)

    By the way, I'm not a student or a teacher - I have a ton of legacy application code to support, most of it not written by me. I've seen some real junk code that's tough to find problems in because good coding standards weren't used.
    Regards,
    Terry

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •