Link to home
Start Free TrialLog in
Avatar of Barretoan
Barretoan

asked on

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

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.


Avatar of valhallatech
valhallatech

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

Glenn
ASKER CERTIFIED SOLUTION
Avatar of valhallatech
valhallatech

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Barretoan

ASKER

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.
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?
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
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.
Interesting - if you've got urls for any of those articles handy, I'd be facinated to have a read.
Thx
Glenn
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.