How do you use Dcount in a macro?

WLC

Registered User.
Local time
Today, 10:29
Joined
Jun 19, 2012
Messages
63
I have a macro that runs a query to find Max date of a table, then (I think) I want to use Dcount to see if that date exists on another table. If it does exist, I want the macro to stop processing and display an error message (i.e. "Error with file"). If it doesn't exist, let the macro continue processing. Can someone give me step by step instructions as I'm fairly new to Access and completely unfamiliar with VBA.

Thank you.
 
I have a macro that runs a query to find Max date of a table, then (I think) I want to use Dcount to see if that date exists on another table. If it does exist, I want the macro to stop processing and display an error message (i.e. "Error with file"). If it doesn't exist, let the macro continue processing. Can someone give me step by step instructions as I'm fairly new to Access and completely unfamiliar with VBA.

Thank you.

I don't understand what you don't know.

Use the DMax function in order to retrieve the Max date
Dim MaxDate As Date
MaxDate = DMax("FieldName","TableName")

where FieldName is the name of the field where you store dates

Then the DCount:
IF DCount("*", "TableName", "FieldName = #" & MaxDate & "#") > 0 THEN
.....
END IF


Note that Access SQL work with dates in USA format
Date format by country - Wikipedia, the free encyclopedia
 
I would add a format to make sure, Mihail.

Code:
DCount("*", "TableName", "FieldName = #" & format(MaxDate, "MM/DD/YYYY") & "#")
 
I don't understand where you put it. I've got the concept down of how to use it. But how do I incorporate it into a macro without using VBA?
 

Users who are viewing this thread

Back
Top Bottom