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

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
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
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,040
Members
449,063
Latest member
ak94

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