On NoData

toleafs

Active Member
Joined
Jun 27, 2005
Messages
498
Hello
Any help is appreciated. I have a macro that runs and exports a query to excel. In there a way to cancel the event if there is no data in the query so it stops running the export process?

thanks
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Trevor G

Well-known Member
Joined
Jul 17, 2008
Messages
6,708
Office Version
  1. 2016
Platform
  1. Windows
What about setting a form to run the query, and add a count feature in the form as an unbound box, and if the record count is 0 then cancel the event

Create a form based on the query, and add a textbox that will count based on a field that will always have something in like an ID field.

Add an if statement to a command button something like this:
docmd.openquery "Query Name"
IF txtcount.value=0 then
exit sub
else
docmd.transferspreadsheet etc
end if
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,683
Messages
5,833,096
Members
430,193
Latest member
Samtk

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
Top