|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
compare # of records in query vs table with if statement
Hello,
I need to write some vba code that compares the number of records in a query versus the number of records in a table. I need it to be executed when a button is click on a form as a sub procedure. Something like the following: private sub eval_click() if the number of records in qrytblone = the number of records in tbltwo then msgbox("OK TO PROCEED WITH INVOICE PROCESSING") ELSE msgbox("NOT OK TO PROCEED WITH INVOICE PROCESSING, PLEASE QUIT APP AND CONTACT ADMIN") end sub Is this possible? |
|
#2
|
|||
|
|||
|
Yes
Use ADO or DAO to open both recordsets Then do If rsTable.RecordCount = Queryrs.RecordCount then msgbox("OK TO PROCEED WITH INVOICE PROCESSING") Else msgbox ("NOT OK TO PROCEED WITH INVOICE PROCESSING, PLEASE QUIT APP AND CONTACT ADMIN") Endif S- |
|
#3
|
|||
|
|||
|
Dim Db As DAO.Database
Dim rstable As DAO.Recordset Dim queryrs As DAO.Recordset Set Db = CurrentDb Set rstable = Db.OpenRecordset("table1", dbOpenDynaset) Set queryrs = Db.OpenRecordset("table2", dbOpenDynaset) If rstable.RecordCount = queryrs.RecordCount Then MsgBox ("OK TO PROCEED WITH INVOICE PROCESSING") Else MsgBox ("NOT OK TO PROCEED WITH INVOICE PROCESSING, PLEASE QUIT APP AND CONTACT ADMIN") End If End If Set rs = Nothing Set Db = Nothing This code does not check the records in the table. it always says "ok to proceed with invoice processing) any suggestions/? |
|
#4
|
||||
|
||||
|
The RecordCount property doesn't tell you how many records are CONTAINED in a dynaset–type Recordset until all records have been ACCESSED.
So if you need to know the number of records in a dynaset–type Recordset then use MoveLast method to reach the last record (and then, if you need to, go back to the record that was previously current). Once the last record has been accessed, the RecordCount property indicates the total number of undeleted records in the Recordset Your IF statement returns True because RecordCount property of both RecordSets remain 0 because you havent't accessed all records.
__________________
BRegs, TBÁrpi "I can only show you the door. You're the one who has to walk through it." Last edited by TBÁrpi : January 13th, 2004 at 11:45 AM. |
|
#5
|
|||
|
|||
|
can you show me how to do it?
|
|
#6
|
|||
|
|||
|
i got it!
it worked GREAT TIP! |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft Access Help > compare # of records in query vs table with if statement |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|