Microsoft Access Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft Access Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 8th, 2004, 10:43 PM
jjb81 jjb81 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 60 jjb81 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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?

Reply With Quote
  #2  
Old January 8th, 2004, 11:00 PM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 12
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-

Reply With Quote
  #3  
Old January 13th, 2004, 11:24 AM
jjb81 jjb81 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 60 jjb81 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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/?

Reply With Quote
  #4  
Old January 13th, 2004, 11:39 AM
TBÁrpi's Avatar
TBÁrpi TBÁrpi is offline
Lazy User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Hungary, Europe
Posts: 337 TBÁrpi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 5 m 5 sec
Reputation Power: 5
Send a message via MSN to TBÁrpi Send a message via Yahoo to TBÁrpi Send a message via Skype to TBÁrpi
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.

Reply With Quote
  #5  
Old January 13th, 2004, 12:46 PM
jjb81 jjb81 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 60 jjb81 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
can you show me how to do it?

Reply With Quote
  #6  
Old January 13th, 2004, 01:03 PM
jjb81 jjb81 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 60 jjb81 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
i got it!
it worked GREAT TIP!

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft Access Help > compare # of records in query vs table with if statement


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT