Solved

Getting Error: No current recocord (3021), How can I get around this error

Posted on 2004-10-26
341 Views
Last Modified: 2012-08-14
How can I get around this error?

Here is the code I am working with and it seems to work ok as long as I put up with this err.

Private Sub CmdSearch_Click()
   'Written by Angelo Barreto 8-21-2004
   'Last modified 10-15-2004
   'Search for records as specified by the criteria entered by & _
   the user.
 On Error GoTo Err_CmdSearch_Click
 
    'Start by setting focus on the & _
    TxtSearch text field if go button is click
    Me![TxtSearch].SetFocus
   
    'Declare variables
    Dim db As DAO.Database
    Dim rstList As DAO.Recordset
    Dim rstResults As DAO.Recordset
    Dim strSQL As String
    Dim intRecCount As Long
   
    Dim strMsg, strStyle, strTitle, strHelp, strCtxt, strResponse As String
    strMsg = "You haven't specified anything to search for!. " & _
    "Do you want to continue?"    ' Define message.
    strStyle = vbYesNo + vbInformation + vbDefaultButton2    ' Define buttons.
    strTitle = "Information"    ' Define title.
    strHelp = "DEMO.HLP"    ' Define Help file.
    strCtxt = 1000    ' Define topic
        ' context & _
        ' Display message.
       
    Dim strMsg2, strTitle2 As String
    Dim lngStyle2, lngCtxt2, lngResponse2 As Long
    strMsg2 = ("No matching record was found." & _
       "Do you want to search again.")  ' Define message.
    lngStyle2 = vbOKOnly + vbInformation + vbDefaultButton1    ' Define buttons.
    strTitle2 = "Information"    ' Define title.
    lngCtxt2 = "1000"    ' Define topic
        ' context & _
        ' Display message.
   
     'Verify if strSearch is not empty & _
     and if it is then prompt user to enter & _
     a search criteria
    If Me![TxtSearch].Value = "" Then
        strResponse = MsgBox(strMsg, strStyle, strTitle, strHelp, strCtxt)
        If strResponse = vbYes Then
            'Set focus on txtsearch text field & _
            Else
            Me![TxtSearch].SetFocus
        Else
            'Set focus on CustomerID text field
            Me![CustomerID].SetFocus
        End If
     'If the txtsearch text field is not empty & _
     then
    Else
       
        'Get current database and
        Set db = CurrentDb
            'Populate strSQL obj
            strSQL = "Select * From tblMBills Where [Ship#_PM] = '" & Nz(Me![TxtSearch].Value) & _
            "' OR [CustomerID] = '" & Nz(Me![TxtSearch].Value) & _
            "' OR [SNAM] = '" & Nz(Me![TxtSearch].Value) & _
            "' OR [Attn] = '" & Nz(Me![TxtSearch].Value) & _
            "' OR [PO#] = '" & Nz(Me![TxtSearch].Value) & _
            "' OR [CTEL] = '" & Nz(Me![TxtSearch].Value) & _
            "' OR [ROE#] = '" & Nz(Me![TxtSearch].Value) & _
            "' OR [Agent] = '" & Nz(Me![TxtSearch].Value) & _
            "' OR [Siebel_Order#] = '" & Nz(Me![TxtSearch].Value) & _
            "' OR [MO#] = '" & Nz(Me![TxtSearch].Value) & _
            "' OR [CC#] = '" & Nz(Me![TxtSearch].Value) & _
            "' OR [Card_Holder_Name] = '" & Nz(Me![TxtSearch].Value) & _
            "' OR [Caller] = '" & Nz(Me![TxtSearch].Value) & "'"

            'Populate rstList variable & _
            with SQL string value or values
            Set rstList = db.OpenRecordset(strSQL)
           
            'If a match is not found then
            If rstList.NoMatch = True Then
              'alert user with a msg & _
              clear the TxtSearch text field and  & _
              set the focus on it & _
              and stop the process
              lngResponse2 = MsgBox(strMsg2, strStyle2, strTitle2, strCtxt2)
              'Clear TxtSearch text field
              Forms![fpriMBills]![TxtSearch] = ""
              Me![TxtSearch].SetFocus
              Exit Sub
             
              'Note: Err.Number = 3021
              'Err.Description = No current record
             
              'STATUS & _
              This behavior is by design. & _
              This design is under review and will be considered for enhancement & _
              in a future release. Perhaps in Access 2003 or above.
             
            'If a match has been found then
            ElseIf rstList.NoMatch = False Then
             'Iterate through the records until EOF & _
             and edit found records and  & _
             store the number of records found in the & _
             intRecCount variable
             Do Until rstList.EOF
                rstList.Edit
                intRecCount = rstList.RecordCount
                rstList.MoveNext
             Loop
                'Transfer the found record or records to the & _
                current form and stop the loop and
                Set Forms(fpriMBills).Recordset = rstList
               'Move to the first record
                rstList.MoveFirst
             
               'Check if the number of found records = 1 then and
               If intRecCount = 1 Then
                 'Display the number record found in a msg else
                 MsgBox (intRecCount & " Record was found.")
               Else
                 'Display the number of records found & _
                 move to 1st record and set focus on CustomerID control
                 MsgBox (intRecCount & " Records were found.")
                 Me![CustomerID].SetFocus
               End If
               
           End If
       
     End If

Exit_CmdSearch_Click:
    Exit Sub

Err_CmdSearch_Click:
     'If Err # 3021(No current record then & _
     Re-populate form by calling & _
     populateform function
     If Err.Number = 3021 Then
      MsgBox Err.Description
        Call Populateform
     'Release system resources & _
     by closing the db and rst variables
     If Not rstList Is Nothing Then
         rstList.Close
         Set rstList = Nothing
     End If
     If Not db Is Nothing Then
         db.Close
         Set db = Nothing
     End If
     
     'Clear TxtSearch text field & _
      set focus on txtsearch text field
      Forms![fpriMBills]![TxtSearch] = ""
      Me![TxtSearch].SetFocus
     Resume Exit_CmdSearch_Click
    Else
   
        Resume Exit_CmdSearch_Click
    End If
End Sub

The Error comes up right after I open the form and click on the "go" button. Once I have click the Go button twice, then the actual code keeps in and everything works ok. Do you have any suggestions?

Note: I am not sure if due this err the code actually is not performing any checks as well.


Thanks for your help.


0
Question by:Barretoan
    8 Comments
     
    LVL 2

    Expert Comment

    by:valhallatech
    Try this - after checking rstList.nomatch = False  do  a rstList.movefirst then

    Glenn
    0
     
    LVL 2

    Accepted Solution

    by:
    Like this?
    --------------------------------------------------------------------------------------------
     ElseIf rstList.NoMatch = False Then
                 'Iterate through the records until EOF & _
                 and edit found records and  & _
                 store the number of records found in the & _
                 intRecCount variable
                 rstList.Movefirst
                 Do Until rstList.EOF
                    rstList.Edit
                    intRecCount = rstList.RecordCount
                    rstList.MoveNext
                 Loop
    --------------------------------------------------------------------------------------------
    or even safer:
    if not (rstList.Eof and rstList.bof) then rstlist.movefirst

    Or perhaps...
    Down a few lines where you have rstLIst.movefirst - is it happening there?

    Also
    You've done a rstList.edit without issueing a rstList.update (though if I recall .movenext will look after that yes? - I can't remember)  but more significantly  I'm not sure why you issued the .edit as I can see where you actually modify a field in  rstList.
    0
     

    Author Comment

    by:Barretoan
    Ok, you have a point on why I have the rstLIst.edit method without having the rstLIst.update also. But after removing the rstLIst.Edit method, it really did not do anything different to address the isssue. The Issue is that let say, a usr is searching for  a X record. If the Customer# entered by the usr, matched the one retrieved by the rstLIst.Recordset(strSQL) statement. Then every thing is Ok. No err here. The problem happend when the usr enters a Customer# that does not match the records in the rstLIst.Recordset(strSQL).

    The Recordset inmediately sees this as an err and it quickly display the "No current record" msg. It ignores the fact that I have put a check rstLIst.nomatch = True then statement there. It jumps to the

    Err_CmdSearch_Click
     MsgBox Err.Description
     Resume Exit_CmdSearch_Click
    End Sub
    statements. Do you have any more clues as to what could be causing this error to ignore the rstLIst.nomatch = true then statment.
    0
     

    Author Comment

    by:Barretoan
    About the rstLIst.nomatch = true then statement, this statement does not stop the err from coming up eventhough I have taken out the Exit Sub statement.

    As you may have the code, there is a msg for almost every statement throughout the code due I want to guide the users as closely as possible to what they can expect to happend after they have taken an action (search).

    Do you know if this is a way for the rst.Recordset method to say that the record doesn't exits in the db?
    0
     
    LVL 2

    Expert Comment

    by:valhallatech
    Ok I'm getting quite confused here & have quite a few things needing clarification. Could you confirm a couple of things for me:

    1) That all your if...else...endif's match up correctly for example in this block - as erroneously placed endif could cause havock with program flow:
       If Me![TxtSearch].Value = "" Then
            strResponse = MsgBox(strMsg, strStyle, strTitle, strHelp, strCtxt)
            If strResponse = vbYes Then
                'Set focus on txtsearch text field & _
                Else  <<<<<< -------------------------------------Is this part of a comment or an else
                Me![TxtSearch].SetFocus
            Else
                'Set focus on CustomerID text field
                Me![CustomerID].SetFocus
            End If
         'If the txtsearch text field is not empty & _
         then
        Else
    2) Have you set a break point and followed the error causing condition through? At which line does the error actually occur (i.e. jump to the error handler)?

    3) At the 'if rstList.nomatch = true' line - what is rstList.eof and rstList.bof

    I have other q's, but would like to know in concrete terms these things.

    Glenn
    0
     

    Author Comment

    by:Barretoan
    What you have high lighted in your comments has nothing to do with the issue. Those are simply comment lines broken into a 2nd line.

    I have come across with about three articles in the Microsoft site that talk about this issue. This seems to be a generic problem with ACC2000 and prior versions.

    I have come up with a work around solution to this issue and it seems to have given me a satisfactory answer.

    I just want to thank you for taking the time to response to this issue that Microsoft Itself is aware off and we will leave as that.

    Thanks anyhow.
    0
     
    LVL 2

    Expert Comment

    by:valhallatech
    Interesting - if you've got urls for any of those articles handy, I'd be facinated to have a read.
    Thx
    Glenn
    0
     

    Author Comment

    by:Barretoan
    Here is one of them:

    http://search.microsoft.com/search/results.aspx?st=b&na=88&View=en-us&qu=No+Current+Record

    and found a lot more in www.google.com by just entering the work "No current record" or the err itselft "3021".


    Anyhow thanks again.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
    A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

    877 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now