Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Use DCOUNT, etc. with dynamic SQL statement in VBA

Posted on 2009-04-13
3
Medium Priority
?
614 Views
Last Modified: 2012-05-06
In a VBA module, I need to get a count of records from a particular recordset, not a table.  Is there some way I can embed the SQL statement in the DCount instead of using a table name?  

Something like the Code sample below?


If DCount("Zip", "SELECT tbl_PostalCodes_US.Zip FROM tbl_PostalCodes_US WHERE (((tbl_PostalCodes_US.Zip)=Left('" & Me.[Zip] & "',5)));") > 1 Then

Open in new window

0
Comment
Question by:DHompster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 24134678
you can use this

If DCount("Zip", "tbl_PostalCodes_US","[Zip]='" & Left(Me.[Zip],5) &"'") > 1 Then
0
 

Author Closing Comment

by:DHompster
ID: 31569767
Duh!  Thanks!  You're solution is perfect for my example.  Unfortunately, I gave a lame example.  What about the idea of substituting a SQL statement (a SELECT stmt) in the place of the table name?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 24134920
No you can not use a select statement, it has to be a table or a saved query as the domain.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we’ll look at how to deploy ProxySQL.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question