Results 1 to 5 of 5
  1. #1
    Snayjay is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2014
    Location
    Gulf of Mexico
    Posts
    10

    No Current Record... I know the record is there...

    Trying to run a Function from a module and I get an error. However, I'm using the same code in another module except using a different table it it works. Which leads me to believe something is wrong with the table.



    Here is my code:

    Code:
        'there is more code above this (just declaring working variables), I've just pulled the part I think is causing the problem 
    
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
        Set db = CurrentDb
        Set rs = db.OpenRecordset("TEMPBILLtbl")
        rs.MoveFirst
        Do Until lastbillpaid = True
            If rs.Fields(20) < 0 Then    'check if workingpayoff is negative
    
        'more code below this
    It's bugging on the highlighted line saying Run-time Error 3021 - No Current Record, but I have tested to see if the table is there and it is.
    I placed "msgbox rs.Fields(20)" after "rs.MoveFirst" and it gives me the correct value from the first record.

    Any help would be greatly appreciated.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    You haven't provided many details regarding your table structure or data. Readers have no idea of where this fits --no business rules or facts to assist with context.
    How many fields are in the table? You're looking at field (20) - which is a large number of fields for a normalized table.

    What is lastbillpaid?

    A few things to consider.
    -always use Option Explicit to ensure all variables are Dimmed
    -use Debug.print or MsgBox to help with debugging.
    - you have options when working with recordsets
    eg rs.Fields("fieldname")
    rs!Fieldname

  3. #3
    Snayjay is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2014
    Location
    Gulf of Mexico
    Posts
    10
    Orange, thanks for the response. I'll just recode it another way, I explained that I did debug using a msgbox and it gave me the data I was looking for, so I have no clue why the next line would result in no records.

  4. #4
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114
    Not sure if this is relevant, but I have documented in other scenarios that record sets dont necessarily form more rapidly than the succeeding code executes. For example, they can behave as expected while stepping through code from a breakpoint, but still show the type of behavior you describe on normal execution. One simple thing to try is to put a move.last before the move.first. If that doesn't work you could try inserting a timer, eg. Via DoEvents.

    FWIW. -Ron

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

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

Similar Threads

  1. Replies: 3
    Last Post: 02-06-2015, 01:18 PM
  2. Replies: 2
    Last Post: 03-05-2014, 05:37 PM
  3. Replies: 16
    Last Post: 02-06-2013, 03:06 PM
  4. Replies: 3
    Last Post: 09-19-2012, 07:34 AM
  5. Replies: 5
    Last Post: 08-24-2012, 10:32 AM

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