473,465 Members | 1,489 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Continuing an Access Macro with Conditions

5 New Member
I have a macro where I do a transfer spreadsheet from some db queries. I only want the macro to create the spreadsheet if there are results in the query. If not, I want the macro to skip that transfer spreadsheet and move on to the next transfer spreadsheet command.

The way I tried fails when there are no records. Basically I did the following on the macro conditon:

DCount("*","query name was here")>0

This works on the queries with records until I hit a query that doesn't have any records. The macro stops and doesn't move on to the next command.

I understand why, I told it to stop, but don't know how to tell it, move on :)

Any ideas? Thanks.
Oct 29 '08 #1
3 5733
emsik1001
93 New Member
Hi

Could you paste your code?

Regards
Emil
Oct 29 '08 #2
Marisol2
5 New Member
Hi--

I'm using a macro that looks like this:

Condition: DCount("*","qry1")>0
Action: OpenQuery
Query Name: Qry1
View: PivotTable
Data Mode: Read Only

Action: Run Command
Command: PivotTableExportToExcel

Action: Close
Object Type: Query
Object Name: Qry1
Save: No

Condition: DCount("*","qry2")>0
Action: OpenQuery
Query Name: Qry2
View: PivotTable
Data Mode: Read Only

Action: Run Command
Command: PivotTableExportToExcel

Action: Close
Object Type: Query
Object Name: Qry2
Save: No

Condition: DCount("*","qry3")>0
Action: OpenQuery
Query Name: Qry3
View: PivotTable
Data Mode: Read Only

Action: Run Command
Command: PivotTableExportToExcel

Action: Close
Object Type: Query
Object Name: Qry3
Save: No


The macro works if all 3 queries have results. But say if qry2 didn't then the macro stops. I need something that tells it, don't produce the export, but move on to the next action with a condition.

Thanks.
Oct 29 '08 #3
ADezii
8,834 Recognized Expert Expert
Hi--

I'm using a macro that looks like this:

Condition: DCount("*","qry1")>0
Action: OpenQuery
Query Name: Qry1
View: PivotTable
Data Mode: Read Only

Action: Run Command
Command: PivotTableExportToExcel

Action: Close
Object Type: Query
Object Name: Qry1
Save: No

Condition: DCount("*","qry2")>0
Action: OpenQuery
Query Name: Qry2
View: PivotTable
Data Mode: Read Only

Action: Run Command
Command: PivotTableExportToExcel

Action: Close
Object Type: Query
Object Name: Qry2
Save: No

Condition: DCount("*","qry3")>0
Action: OpenQuery
Query Name: Qry3
View: PivotTable
Data Mode: Read Only

Action: Run Command
Command: PivotTableExportToExcel

Action: Close
Object Type: Query
Object Name: Qry3
Save: No


The macro works if all 3 queries have results. But say if qry2 didn't then the macro stops. I need something that tells it, don't produce the export, but move on to the next action with a condition.

Thanks.
What you attempting to do may be a little hairy with a Macro. Assuming the Queries you wish to process are prefaced with 'Qry', why not use a more efficient code based approach, something similar to:
Expand|Select|Wrap|Line Numbers
  1. Dim qdf As DAO.QueryDef
  2. Dim MyDB As Database
  3. Const conDIR_TO_TRANSFER_TO As String = "C:\Test\"
  4.  
  5. Set MyDB = CurrentDb
  6.  
  7. For Each qdf In MyDB.QueryDefs
  8.   If Left$(qdf.Name, 3) = "Qry" Then        'Filter only your Queries
  9.     If DCount("*", qdf.Name) > 0 Then       'Does the Query produce Records?
  10.       DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, qdf.Name, _
  11.                                 conDIR_TO_TRANSFER_TO & qdf.Name & ".xls", True
  12.     End If
  13.   End If
  14. Next
Oct 29 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Pete | last post by:
In Access 95/97 I used to be able to create pull down menus (File,Edit ...) from a macro. It seems there used to be some wizard for that. However in Access 2000 it seems you have to build your...
49
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are questionning/validating the use of MS Access as front-end. The...
6
by: steve lord | last post by:
Greetings all, I have a macro that should add a column to a table if the column doesn't already exist. Using the macro condition, how can I test for whether a specific column name in a specific...
7
by: Tobin Fricke | last post by:
I have a wrapper function I use to check the error conditions of various functions: wrap(foo(1,2,3)); (1) while (1 == wrap(bar("fluffy"))) { ... } (2)...
2
by: Russell G | last post by:
Hi I have a number of queries that I have included in a macro. I wish to run this macro at a certian time, usually after hours. I have been playing around with the RUNMACRO command and the...
3
by: swb76 | last post by:
Hi, I have 6 queries in Access that run great. They need to be run in sequence with the first 5 queries writing to tables and the sixth one pops up the final results in datasheet view. Now, how...
1
by: Paldrion | last post by:
I will need it to be in VBA, since I need to put it in an Access 2007 database and execute it with an Access macro. What I am doing is using a utility to find the hard drives' conditions on...
11
by: helraizer1 | last post by:
Hi folks, I have a system for an auctioneer and have on the form I have the fields: lot (the item), reserve price () and minimum successful bid so far (). There is then a text box for the user to...
5
by: Peng Yu | last post by:
Hi, It is benifitical to use macro in certain cases. http://www.boost.org/doc/libs/1_35_0/libs/preprocessor/doc/index.html However, I found that it is not easy to debug a macro. For example,...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.