Forum Discussion

Gilgamesh1964's avatar
Gilgamesh1964
Brass Contributor
Dec 04, 2025

How do I reference query data from an Access Macro

I have a simple Select query that returns a number of records.

In my Access macro (just for clarification, I do mean Access Macro and not VBA) I want to check how many records the query returns in an IF statement.

In this specific case the check would be on zero returned records, but being able to check non-zero in the future might be useful.

I have tried various internet searches but the only results I found relate to VBA.

Suggestions on how to do this check would be appreciated.

Thank You

2 Replies

  • XPS35's avatar
    XPS35
    Iron Contributor

    In my Dutch Access a macro could look like this

    "Berichtvak" means "Messagebox"

  • Hi,

    You can use the DCount function in your macro to get the number of returned records of the query, like this:

    If DCount("*","YourQueryNameHere")=0 Then

        [some action here]

    Non zero would of course be: >0

    Depending on your regional settings, i.e. the Windows list separator, you may have to use the semicolon instead of the comma as separator in the DCount function.

    Servus
    Karl
    ****************
    Access Forever News DevCon
    Access-Entwickler-Konferenz AEK

Resources