473,385 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Recordset .EOF returning true when there are multiple records

rsmccli
52
Access 2002
Hi. I have a command button that will "approve" all records currently being looked at by an "approver". For some reason, even though there are multiple records that exist in the recordsetclone, EOF is returning true. I think this may have something to do with the sort order of the underlying query, but I'm not sure; at any rate, I don't want to change the sort order. I thought you had to check for BOF and EOF, or at least EOF before doing any recordset "Move" type commands. If I stop the code after declaring the recordset and do a recordcount, it says that there are records in the recordset, but no looping occurs because EOF returns True.

I don't get it. I would appreciate any help. Here is the code behind the command button.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdApproveAll_Click()
  2. Dim db As DAO.database
  3. Dim rs As DAO.Recordset
  4. Set db = CurrentDb
  5. Set rs = Me.Child.Form.RecordsetClone
  6.  
  7. With rs
  8.   If Not .BOF And Not .EOF Then
  9.     .MoveFirst
  10.       Do Until .EOF = True
  11.         If .Fields("New") = True Then
  12.           .Edit
  13.           .Fields("Approved") = True
  14.           .Fields("Approver") = CurrentUser()
  15.           .Fields("AppDenDate") = Now()
  16.           .Fields("Denied") = False
  17.           .Update
  18.           .MoveNext
  19.         Else
  20.           .MoveNext
  21.         End If
  22.       Loop
  23.   Else
  24.   End If
  25. End With
  26.  
  27. rs.Close
  28. Set rs = Nothing
  29. Set db = Nothing
  30.  
  31. Me.Requery
  32.  
  33. End Sub
Apr 28 '08 #1
3 6605
Stewart Ross
2,545 Expert Mod 2GB
Hi. Recordsets are usually very predictable, and do not behave as you appear to be experiencing. I think you will need to do some systematic debugging here. Establish the facts first: does the RecordsetClone actually return records? Add the following lines after the recordsetclone line (shown for clarity):
Expand|Select|Wrap|Line Numbers
  1. Set rs = Me.Child.Form.RecordsetClone
  2. rs.movelast
  3. rs.movefirst
  4. msgbox "Recordcount is " & rs.recordcount & " - EOF is " & rs.eof
The messagebox should show the record count and the status of the EOF property. If the messagebox shows a non-zero value yet EOF returns -1 (True) there is a problem with the database. If the recordcount is 0 then EOF will also be True (-1). If this is the case there are no records in the recordsetclone recordset, and you need to investigate why.

-Stewart
Apr 28 '08 #2
Stewart Ross
2,545 Expert Mod 2GB
Hi again. I should have remembered that trying to move to a record in an empty recordset will cause an error, so add
Expand|Select|Wrap|Line Numbers
  1. on error resume next
at the top of the debug code to avoid interrupting the messagebox display in the event that the recordset really is empty. You can take all additional statements you put in out again after the source of the error is found.

You probably know already, but just to explain why Movelast is immediately followed by Movefirst: if the recordset is based on a table then the Recordcount property is accurate, but if it is based on a query (as all forms should be) the Recordcount property does not return a fully accurate value unless the full recordset has been traversed first - hence the Movelast. This is followed by Movefirst to reset the record pointer to the first record in the recordset, ready for loop processing.

-Stewart
Apr 29 '08 #3
rsmccli
52
Thank you for your help.
Apr 29 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: shank | last post by:
I have a recordset that contains multiple records of product a user is purchasing. For clarity, I converted the recordset fields to variables. I need to take that entire recordset and insert it...
2
by: JMCN | last post by:
i am running into problems with is the recordset. i have exactly 104 records. when i tested the code, the end result was multiple records for the same loan(ET LN Shortname). where did i go wrong? ...
5
by: Kaur | last post by:
Hi, I have been successful copying a vba code from one of your posts on how to copy and paste a record by declaring the desired fields that needs to be copied in form's declaration and creating two...
13
by: agent-s | last post by:
I have a function, generally described as so: def function(args): if condition: if condition2: function(args+1) elif condition3: print "text" return True else:
0
chumlyumly
by: chumlyumly | last post by:
Hello scripters - OS: Mac OSX Language: PHP w/ MySQL database I've created an insert page where a user inputs his info, which then goes to four different tables in a MySQL database. The...
8
by: jmarcrum | last post by:
Hello all, i have a continuous form that displays about 1000 records and opens when I click a button. When the form opens, the user has the option of checking a checkbox that is located beside...
2
by: phill86 | last post by:
Hi, i have a recordset that updates a table which works fine when you add, update and paste a single record but if you try and paste multiple records it will only update the table with the...
3
by: uma9 | last post by:
hi, the code below is used to insert a single record....i want to know how to insert multiple records using a "for" loop...please help Set connect = CreateObject ("ADODB.Connection")...
4
by: phill86 | last post by:
Hi, i have a form that runs a query in a recordset on the after update method if i copy and paste one record at a time the query picks up the records in the underlying table but if i paste...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.