Query result with no Data, options?

jarett

Board Regular
Joined
Apr 12, 2021
Messages
165
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a query running and exporting through "AutoExec" then through some batch scripts renaming the file and dropping on an ftp site. I scheduled all these task to run through task scheduler so I could have the least amount of interaction possible. However, sometimes when the task runs the query and goes through all the steps, some files end up not having any data (no new data had been entered since the last time the query was run). Is there anywhere in the process that I could stop the "file" if it has no data? I have a header line which I could possibly leave off, didn't know if I could stop the export in Access or if I would have to do somewhere in the scripts.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
I found this article, Scanning inside an Excel report, and it is basically what I want to do. I've never used PS before so is this the only way or can I do through a .bat? Or if someone has a simpler explanation than the link listed.
 
Upvote 0
It really depends on how your "AutoExec" works. For instance, if its a simple "run this query" basically, then no you cannot stop it if there is no data in the result, because you don't know what the result is until after you run it.

Generally however, this is easily handled in your batch scripts. They can check for empty files or files with only one line in them (truly empty files are easier then files with only a header in them ... you can just check for file size of zero bytes, but it shouldn't be be a problem either way).

Also it can be handled with more complicated macros that are built for you AutoExec actions (either with MSAccess Macros or MSAccess VBA)
 
Upvote 0
I've tried this code but to no avail, a lot of the articles or on counting lines in txt files, do the same scripts not work for xlsx files?
Code:
@echo off
pushd "O:\Purchase Orders\z-POs\Automated_PO\Lapco_Sent\"
for /f "tokens=1*" %%A in (
  'find /c /v "" *.xlsx^|findstr /rc:" [01]$"'
) do for /f "delims=:" %%F in ("%%B") do del "%%F"
popd

I am not positive on my use of the "tokens=1*" or the line with the findstr /rc:" [01]$"'
 
Upvote 0
if your output files are xlsx then I don't think such a script is an option unless you are specifically looking at a script that was written for excel files. Generally, scripting solution assume text files (such as csv files) in cases like this.
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,438
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top