Results 1 to 5 of 5
  1. #1
    AccessPower's Avatar
    AccessPower is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2016
    Posts
    165

    Ugh - No Current Record 3021

    Hello Everyone! again... lol

    I have the following code:

    Code:
       
       Dim Number5 As String   Dim Number7 As String
       Dim Number9 As String
       Dim MiddleNumberstoMatch As Integer
       Dim MatchCheck As Integer
       Dim i As Integer
       Dim SQL5 As String
       Dim SQL7 As String
       Dim SQL9 As String
       Dim RS5 As Recordset
       Dim RS7 As Recordset
       Dim RS9 As Recordset
    
    
       SQL5 = "SELECT " + SelectedTable + ".Numbers, Val(Mid(Numbers,2)) AS JustNumbers, Val(LEFT(JustNumbers, len(JustNumbers)-1)) AS Numbers_to_Match FROM " + SelectedTable + " WHERE Right([Numbers],1)='5' ORDER BY Numbers;"
       SQL7 = "SELECT " + SelectedTable + ".Numbers, Val(Mid(Numbers,2)) AS JustNumbers, Val(LEFT(JustNumbers, len(JustNumbers)-1)) AS Numbers_to_Match FROM " + SelectedTable + " WHERE Right([Numbers],1)='7' ORDER BY Numbers;"
       SQL9 = "SELECT " + SelectedTable + ".Numbers, Val(Mid(Numbers,2)) AS JustNumbers, Val(LEFT(JustNumbers, len(JustNumbers)-1)) AS Numbers_to_Match FROM " + SelectedTable + " WHERE Right([Numbers],1)='9' ORDER BY Numbers;"
    
    
       Set RS5 = CurrentDb.OpenRecordset(SQL5)
       Set RS7 = CurrentDb.OpenRecordset(SQL7)
       Set RS9 = CurrentDb.OpenRecordset(SQL9)
       
       RS5.OpenRecordset
       RS5.MoveFirst
       If Not RS5.EOF Then
       
    ResetLabel:
        MiddleNumberstoMatch = RS5!Numbers_to_match
        Number5 = RS5!Numbers
            RS7.MoveFirst
            If Not RS7.EOF Then
                
    ResetLabel7:
                MatchCheck = RS7!Numbers_to_match
                If MatchCheck = MiddleNumberstoMatch Then
                    Number7 = RS7!Numbers
                    RS9.MoveFirst
                    If Not RS9.EOF Then
    ResetLabel9:
                        MatchCheck = RS9!Numbers_to_match
                        If MatchCheck = MiddleNumberstoMatch Then
                            Number9 = RS9!Numbers
                            'Me.txtSwitchNumber = Number5
                            Me.txtSwitchNumber1 = Number5
                            Me.txtSwitchNumber2 = Number7
                            Me.txtSwitchNumber3 = Number9
                            RS5.Close
                            RS7.Close
                            RS9.Close
                        Else
                            RS9.MoveNext
                            GoTo ResetLabel9
                        End If
                    Else
                        RS5.MoveNext
                        GoTo ResetLabel
                    End If
                Else
                    RS7.MoveNext
                    GoTo ResetLabel7
                End If
            Else
                RS5.MoveNext
                GoTo ResetLabel
            End If
        Else
        RS5.Close
        RS7.Close
        RS9.Close
        MsgBox "There are no matching records in the recordset that meet the criteria."
        End If
    So, the above code trips on line: MatchCheck = RS7!Numbers_to_match



    There are definitely records that match. Can anyone see why this would pull such an error? I am about to pull out the rest of my hair. Thank you in advance!
    Last edited by AccessPower; 12-08-2016 at 04:00 PM.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can use this to debug:

    BaldyWeb-Immediate window

    You don't need the MoveFirst, and it will error on an empty recordset.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    AccessPower's Avatar
    AccessPower is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2016
    Posts
    165
    pbaldy,

    Thank you for the assistance. I looked at the immediate window. It seems as though it has iterated through the entire recordset. It is funny though, because it works for a few tables, but not others. It is not pulling up any records. I'm going to have to see if it has something to do with the left join used.

  4. #4
    AccessPower's Avatar
    AccessPower is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2016
    Posts
    165
    Update:

    Debug.Print MiddleNumberstoMatch & " - " & MatchCheck

    Show that the code is stopping at 002 - 999

    This means that the middlenumbertomatch (Or in other words RS5.Numbers_to_match) isn't going to to the next record. This is the point of these loops nested within the loops. I don't know why the loop stops. It really should end up 999 - 999. There is only one record in RS5 that has the middle numbers of 002. Can anyone see why the loop isn't working?

    This should function like a brute force mechanism.

  5. #5
    AccessPower's Avatar
    AccessPower is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2016
    Posts
    165
    I also tried this approach. There is quite a bit less code. It is looking for everything between a letter and the last number and making sure there is a sequence of three numbers with endings of 5,7,9

    Code:
    Dim Number5 As String
    Dim Number7 As String
    Dim Number9 As String
    
    
    Dim i As Integer
    Dim MiddleNumberstoMatch As String
    
    
    Dim SQL5 As String
    Dim SQL7 As String
    Dim SQL9 As String
    
    
    Dim RS5 As DAO.Recordset
    Dim RS7 As DAO.Recordset
    Dim RS9 As DAO.Recordset
    
    
    SQL5 = "SELECT " + SelectedTable + ".Numbers, Val(Mid(Numbers,2)) AS JustNumbers, LEFT(JustNumbers, len(JustNumbers)-1) AS Numbers_to_Match FROM " + SelectedTable + " LEFT JOIN qryMPCSwitches5 ON " + SelectedTable + ".Numbers = qryMPCSwitches5.LOC_NUM WHERE Right([Numbers],1)='5';"
    
    
    
    
    Set RS5 = CurrentDb.OpenRecordset(SQL5)
    Set RS9 = CurrentDb.OpenRecordset(SQL9)
       
    RS5.OpenRecordset
    RS5.MoveFirst
    
    
    
    
    ResetLabel:
    If Not RS5.EOF Then
        MiddleNumberstoMatch = RS5!Numbers_to_match
        Number5 = RS5!Numbers
    
    
        SQL7 = "SELECT " + SelectedTable + ".Numbers, Val(Mid(Numbers,2)) AS JustNumbers, LEFT(JustNumbers, len(JustNumbers)-1) AS Numbers_to_Match FROM " + SelectedTable + " LEFT JOIN qryMPCSwitches5 ON " + SelectedTable + ".Numbers = qryMPCSwitches5.LOC_NUM WHERE Numbers LIKE '*" & MiddleNumberstoMatch & "7';"
        Set RS7 = CurrentDb.OpenRecordset(SQL7)
        Debug.Print SQL7
    
    
        If Not RS7.EOF Then
            Number7 = RS7!Numbers
            SQL9 = "SELECT " + SelectedTable + ".Numbers, Val(Mid(Numbers,2)) AS JustNumbers, LEFT(JustNumbers, len(JustNumbers)-1) AS Numbers_to_Match FROM " + SelectedTable + " LEFT JOIN qryMPCSwitches5 ON " + SelectedTable + ".Numbers = qryMPCSwitches5.LOC_NUM WHERE Numbers LIKE '*" & MiddleNumberstoMatch & "9';"
            Set RS9 = CurrentDb.OpenRecordset(SQL9)
            
            If Not RS9.EOF Then
                Number9 = RS9!Numbers
                MsgBox "We found a match!"
            Else
                        RS5.MoveNext
                        GoTo ResetLabel
            End If
        Else
                RS5.MoveNext
                    GoTo ResetLabel
            End If
    Else
        RS5.Close
        RS7.Close
        RS9.Close
        MsgBox "There are no matching records in the recordset that meet the criteria."
    End If

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Runime Error '3021': - No current record
    By Mohanss82 in forum Programming
    Replies: 2
    Last Post: 07-04-2016, 02:34 AM
  2. No current recpord. 3021
    By gg80 in forum Programming
    Replies: 11
    Last Post: 05-05-2015, 07:05 PM
  3. sql error . runtime 3021 - no current record
    By princess12 in forum Access
    Replies: 3
    Last Post: 04-10-2015, 09:26 AM
  4. Error 3021 no current record
    By bbrazeau in forum Programming
    Replies: 10
    Last Post: 12-13-2012, 04:22 PM
  5. Replies: 8
    Last Post: 05-16-2011, 06:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums