Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-10-26
8
Medium Priority
?
350 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
Comment
Question by:Barretoan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 2

Expert Comment

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

Glenn
0
 
LVL 2

Accepted Solution

by:
valhallatech earned 150 total points
ID: 12420076
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
ID: 12429331
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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:Barretoan
ID: 12429430
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
ID: 12431478
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
ID: 12449860
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
ID: 12450164
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
ID: 12460268
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

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

609 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