Finding a matching record in a table using VBA

W

Wally

I'm using A2000
I have a Select Query that is as follows;

SELECT Count(*) AS CountAll
FROM HOLIDAYS
WHERE (((HOLIDAYS.KeyDate)=[IncrementedDate]));

The name of the Query is [qryCount]
There are no duplicate values in this table.

In VBA code behind a textbox control on a form
(AfterUpdate Event) I have some code that needs to know
the results of this Query. How do I run this query within
this event procedure and get the results, which will be
either (1 or 0) or (true or false).

The variable [IncrementedDate] is a local variable that
contains the date in which I need to find in the table
[Holidays]. Of course when I run this query from design
view I have to type in the date value I'm looking for.

Any help or advice anyone can give is greatly appreciated.

Wally
 
M

Marshall Barton

Wally said:
I'm using A2000
I have a Select Query that is as follows;

SELECT Count(*) AS CountAll
FROM HOLIDAYS
WHERE (((HOLIDAYS.KeyDate)=[IncrementedDate]));

The name of the Query is [qryCount]
There are no duplicate values in this table.

In VBA code behind a textbox control on a form
(AfterUpdate Event) I have some code that needs to know
the results of this Query. How do I run this query within
this event procedure and get the results, which will be
either (1 or 0) or (true or false).

The variable [IncrementedDate] is a local variable that
contains the date in which I need to find in the table
[Holidays]. Of course when I run this query from design
view I have to type in the date value I'm looking for.

You should be able to use DCount to do this:

IsHoliday = DCount("*", "HOLIDAYS", _
"KeyDate = " & Format(IncrementedDate, "\#m\/d\/yyyy\#"))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top