Macro Conditional Expressions

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a query that finds if an employee's qualifications have expired and
shows a form and alert at startup with a macro named as autoexec.
Unfortunately it shows the message even if there is no expired employees.

My question is how do I not run the macro when it does not meet a criteria?
I have tried setting a condition but for some reason it doesn't work on a
query??

Thank you in advance STeve
 
The criteria should work. Can you post what you have? I would expect
something like

DCount("*", "Queryname") > 0


"Steve Murphy (Kuwait in Army**US)"
 
I tried "[expired]![Badge]>0" Then got the following error "You may have
specified a control that wasn't on the current object" the it gives the
example to specify the location for example "Forms![expired]![Badge]>0"
However when I type the location "Queries![expired]![Badge]>0" it
automatically changes it to "[Queries]![expired]![Badge]>0" So I am stuck and
at a loss.

Steve
 
Steve -

Can you post the SQL statement of the query that you're trying to use? Open
the query in design view, change to SQL view (icon at top left on toolbar),
and copy the statement that you see there.

It appears that you want to test for the Badge field in the table expired to
be a certain value. The normal syntax for that is
[expired].[Badges] > 0

--

Ken Snell
<MS ACCESS MVP>

"Steve Murphy (Kuwait in Army**US)"
I tried "[expired]![Badge]>0" Then got the following error "You may have
specified a control that wasn't on the current object" the it gives the
example to specify the location for example "Forms![expired]![Badge]>0"
However when I type the location "Queries![expired]![Badge]>0" it
automatically changes it to "[Queries]![expired]![Badge]>0" So I am stuck
and
at a loss.

Steve

JohnFol said:
The criteria should work. Can you post what you have? I would expect
something like

DCount("*", "Queryname") > 0


"Steve Murphy (Kuwait in Army**US)"
 
SELECT Employees.Badge, Employees.FirstName, Employees.LastName,
Employees.Department, TraninigRecord.[Due Date], TraninigRecord.Date,
TraninigRecord.Function, TraninigRecord.[Due Date],
TraninigRecord.Department, Employees.Title
FROM Employees LEFT JOIN TraninigRecord ON Employees.Badge =
TraninigRecord.Badge
WHERE (((TraninigRecord.[Due Date])<Date()));


Ken Snell said:
Steve -

Can you post the SQL statement of the query that you're trying to use? Open
the query in design view, change to SQL view (icon at top left on toolbar),
and copy the statement that you see there.

It appears that you want to test for the Badge field in the table expired to
be a certain value. The normal syntax for that is
[expired].[Badges] > 0

--

Ken Snell
<MS ACCESS MVP>

"Steve Murphy (Kuwait in Army**US)"
I tried "[expired]![Badge]>0" Then got the following error "You may have
specified a control that wasn't on the current object" the it gives the
example to specify the location for example "Forms![expired]![Badge]>0"
However when I type the location "Queries![expired]![Badge]>0" it
automatically changes it to "[Queries]![expired]![Badge]>0" So I am stuck
and
at a loss.

Steve

JohnFol said:
The criteria should work. Can you post what you have? I would expect
something like

DCount("*", "Queryname") > 0


"Steve Murphy (Kuwait in Army**US)"
I have a query that finds if an employee's qualifications have expired
and
shows a form and alert at startup with a macro named as autoexec.
Unfortunately it shows the message even if there is no expired
employees.

My question is how do I not run the macro when it does not meet a
criteria?
I have tried setting a condition but for some reason it doesn't work on
a
query??

Thank you in advance STeve
 
Ken, the query work I think pretty good it only gives me the information I
want based on the expiration date. However, what I want is the atoexec macro
to not run if there is no data to report at start up.

Steve

Ken Snell said:
Steve -

Can you post the SQL statement of the query that you're trying to use? Open
the query in design view, change to SQL view (icon at top left on toolbar),
and copy the statement that you see there.

It appears that you want to test for the Badge field in the table expired to
be a certain value. The normal syntax for that is
[expired].[Badges] > 0

--

Ken Snell
<MS ACCESS MVP>

"Steve Murphy (Kuwait in Army**US)"
I tried "[expired]![Badge]>0" Then got the following error "You may have
specified a control that wasn't on the current object" the it gives the
example to specify the location for example "Forms![expired]![Badge]>0"
However when I type the location "Queries![expired]![Badge]>0" it
automatically changes it to "[Queries]![expired]![Badge]>0" So I am stuck
and
at a loss.

Steve

JohnFol said:
The criteria should work. Can you post what you have? I would expect
something like

DCount("*", "Queryname") > 0


"Steve Murphy (Kuwait in Army**US)"
I have a query that finds if an employee's qualifications have expired
and
shows a form and alert at startup with a macro named as autoexec.
Unfortunately it shows the message even if there is no expired
employees.

My question is how do I not run the macro when it does not meet a
criteria?
I have tried setting a condition but for some reason it doesn't work on
a
query??

Thank you in advance STeve
 
Ah, so you need a condition in the AutoExec macro.

Macro: AutoExec

Condition: DCount("*", "NameOfYourQuery") > 0
Action: OpenQuery
Query Name: "NameOfYourQuery"


--

Ken Snell
<MS ACCESS MVP>

"Steve Murphy (Kuwait in Army**US)"
Ken, the query work I think pretty good it only gives me the information I
want based on the expiration date. However, what I want is the atoexec
macro
to not run if there is no data to report at start up.

Steve

Ken Snell said:
Steve -

Can you post the SQL statement of the query that you're trying to use?
Open
the query in design view, change to SQL view (icon at top left on
toolbar),
and copy the statement that you see there.

It appears that you want to test for the Badge field in the table expired
to
be a certain value. The normal syntax for that is
[expired].[Badges] > 0

--

Ken Snell
<MS ACCESS MVP>

"Steve Murphy (Kuwait in Army**US)"
I tried "[expired]![Badge]>0" Then got the following error "You may have
specified a control that wasn't on the current object" the it gives the
example to specify the location for example "Forms![expired]![Badge]>0"
However when I type the location "Queries![expired]![Badge]>0" it
automatically changes it to "[Queries]![expired]![Badge]>0" So I am
stuck
and
at a loss.

Steve

:

The criteria should work. Can you post what you have? I would expect
something like

DCount("*", "Queryname") > 0


"Steve Murphy (Kuwait in Army**US)"
I have a query that finds if an employee's qualifications have
expired
and
shows a form and alert at startup with a macro named as autoexec.
Unfortunately it shows the message even if there is no expired
employees.

My question is how do I not run the macro when it does not meet a
criteria?
I have tried setting a condition but for some reason it doesn't work
on
a
query??

Thank you in advance STeve
 
Back
Top