Solved

checking to see if a query/table in Access has any rows

Posted on 2014-09-16
3
252 Views
Last Modified: 2014-09-16
Experts,

I have a query in Microsoft Access that is later used to export to Excel.  Is there a way I can tell if rows were returned?  If no rows are returned, I do not want to export the table.
0
Comment
Question by:morinia
[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
3 Comments
 
LVL 24

Assisted Solution

by:Phillip Burton
Phillip Burton earned 100 total points
ID: 40325247
Only if you are using VBA and can use the Recordset.RecordCount property.

If you are not using VBA, then you could build a form to show you how many records there are, and have a button linking to the Export to Excel code, and you can manually see if there are zero records or not.
0
 
LVL 58

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 100 total points
ID: 40325278
Simplest way:

  If DCount("*","<queryname>") >1 then
     ' Do the Export
 End If

Jim.
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 300 total points
ID: 40325279
you can use

if dcount("*","queryName")>0 then
  'export to excel
  else
   msgbox "No records to export
end if
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

717 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