ms access - DAO.Recordset.RecordCount property not working as expected -


i running query input form. extract records 1 table, table joined 3 others.
extract record. in case there 1 record , query find it. problem every time run code, 1 more recordcount. first time run it, recordcount 1 , debug.print gives me correct information. second time run it, recordcount 2 , debug.print gives me correct information twice. third time ... 3 , 3, etc. doesn't matter if close form (from variables) , reload it. number keeps climbing. closed access , reopened , number keeps climbing - didn't reset 1 record found.

the query selects records depending on productid (qtyordered - qtyproduced > 0) , records sorted priority of customers.

dim rs dao.recordset     dim db dao.database      dim findcsql string      findcsql = "select tblwarehousetransfers.wtrproductid, tblorderdetails.odepriority, tblorderdetails.odequantityordered, " _                         & " tblorderdetails.odeqtyproduced, tblcustomers.companyname " _                 & "  tblcustomers inner join (tblorders inner join (tblwarehousetransfers inner join tblorderdetails " _                         & " on tblwarehousetransfers.wtrproductid = tblorderdetails.odeproductfk) " _                         & "  on tblorders.ordorderid = tblorderdetails.odeorderid) on tblcustomers.id = tblorders.ordcustomerid " _                 & " (((tblwarehousetransfers.wtrproductid) = " & chr$(34) & me!cbotransferproductid & chr$(34) & ")) " _                 & " , ((tblorderdetails.odequantityordered - tblorderdetails.odeqtyproduced)> 0) " _                 & " order tblorderdetails.odepriority "       set rs = db.openrecordset(findcsql)      rs.movefirst     debug.print rs.recordcount      while not rs.eof       debug.print ("product id: " & rs!wtrproductid & " qty ordered: " & rs!odequantityordered & " customer name:  " & rs!companyname)       rs.movenext     loop      rs.close     set rs = nothing 

how can empty recordset , start fresh each time subroutine run?

my memory might off since it's been long time since i've worked recordsets, think had traverse records before recordcount property gave correct information.

so try way:

rs.movelast debug.print rs.recordcount rs.movefirst 

from how to: count number of records in dao recordset

the value of recordcount property equals number of records have actually been accessed.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -