Finding a matching record in a table using VBA

  • Thread starter Thread starter Wally
  • Start date Start date
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
 
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\#"))
 
Back
Top