Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Location
    CT,USA
    Posts
    250

    Wink Unanswered: ADO/DAO db recordsets; request for DAO Connection ie

    My first problem was an error on "Type Mismatch" while opening a record set. This is solved by MS article http://support.microsoft.com/?kbid=181542. My current problem is implementing the solution.

    Dim rstNoAddr As Recordset
    Dim dbs As Database
    Dim rstLastAddr As Recordset
    Dim rst As Recordset

    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset(strSQL)
    rst.MoveFirst

    'no problem with above

    Set rstLastAddr = dbs.OpenRecordset(strSQL)

    'error on either statement below = Error number 3021: No Current Record
    rstLastAddr.MoveFirst
    rstLastAddr.MoveLast


    The only difference between recordsets is the following:
    rstLastAddr.FindFirst
    which, I believe makes it an DAO recordset. My research tells me that I will need a Connection to the database to fill the recordset. Can somebody give me an example, I've never needed to do this before now.

    TIA

    PS-- I'm using MS Access 2002 on an XP.

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    Exactly as the error states....No Current Record.

    Without knowing what you are truely trying to do, we can only dance with the error at hand. Off the top I'ld say...there simply is no record to be found based on the supplied query (strSQL). You should be checking for this condition and you can do it this way:

    If stLastAddr.RecordCount > 0 Then
    You processing code here...
    End If


    .
    Environment:
    Self Taught In ALL Environments.....And It Shows!


  3. #3
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    your code is DAO, so you should make your declarations explicitly DAO to avoid any risk of attempting to open an ADO recordset on a DAO database object:
    Dim rstNoAddr As DAO.Recordset
    Dim dbs As DAO.Database
    Dim rstLastAddr As DAO.Recordset
    Dim rst As DAO.Recordset

    CynerLynx' method for zero records should work, however, my preference is:
    if rstLastAddr.bof and rstLastAddr.eof then
    msgbox "there were no records returned"
    else
    rstLastAddr.movelast
    msgbox "there were " & rstLastAddr.recordcount & " records returned"

    izy
    currently using SS 2008R2

  4. #4
    Join Date
    Feb 2004
    Location
    CT,USA
    Posts
    250

    My bad

    I messed up in a query the Nth time thru it was different than the all predecessors. The where search string was missing in the Nth condition. I was thinking it was constant.

    Your replies were dead on. Thanks for the help.

Posting Permissions

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