cheking existing data for previous month

  • Thread starter Thread starter Alex
  • Start date Start date
A

Alex

I have a temporary table with dates in the Day column. I
need to delete and download data there from the original
table if there is not whole previous month.

I've created a query (checking whether it's empty) with
the following restriction in criteria for the Day field to
check it to avoid unnecessary downloading:
DateSerial(Year(Date()),Month(Date())-1,1) And <DateSerial
(Year(Date()),Month(Date()),1)

Please, advise whether it's correct.

Thanks
 
That will tell you if there is at least one record in the time frame.

To have a "whole" month, do you need at least one record for every day in the
month? Or at least one record for the 1st day and one for the last day of the
month? Or exactly one record for every day of the month?

Please define what you mean by a "Whole month".
 
For that I would use criteria that gets the last of the previous month,

Year(Date()),Month(Date()),0)

You could use one of the Aggregate functions, such as

DCOUNT("*","[YourTempTableName]","[Day] =Year(Date()),Month(Date()),0)")

If DCount returns anything that is less than 1, then there is NO record in the
table that has a date equal to the last day of the previous month.

Are you trying to do this in VBA code, or are you trying to do this all in the
SQL Append Statement?

If DCOUNT("*","[YourTempTableName]","[Day] =Year(Date()),Month(Date()),0)") <
1 Then

'Run your append query

End if

Of course it gets a bit more complex, if your date field is also storing a
time. Since then you have to do something more like your original criteria in
filter section of the DCount.
 
Thanks, It's working but with DateSerial added.

-----Original Message-----
For that I would use criteria that gets the last of the previous month,

Year(Date()),Month(Date()),0)

You could use one of the Aggregate functions, such as

DCOUNT("*","[YourTempTableName]","[Day] =Year(Date ()),Month(Date()),0)")

If DCount returns anything that is less than 1, then there is NO record in the
table that has a date equal to the last day of the previous month.

Are you trying to do this in VBA code, or are you trying to do this all in the
SQL Append Statement?

If DCOUNT("*","[YourTempTableName]","[Day] =Year(Date ()),Month(Date()),0)") <
1 Then

'Run your append query

End if

Of course it gets a bit more complex, if your date field is also storing a
time. Since then you have to do something more like your original criteria in
filter section of the DCount.
Thanks for your response, John.

I need at least the last day of the month.

Regards,

Alex
the
time frame. record
for every day in the field
to
.
 
Yeah, I seem to have forgotten to enter that part. What can I say, except "DUUUUH!!!"
Thanks, It's working but with DateSerial added.
-----Original Message-----
For that I would use criteria that gets the last of the previous month,

Year(Date()),Month(Date()),0)

You could use one of the Aggregate functions, such as

DCOUNT("*","[YourTempTableName]","[Day] =Year(Date ()),Month(Date()),0)")

If DCount returns anything that is less than 1, then there is NO record in the
table that has a date equal to the last day of the previous month.

Are you trying to do this in VBA code, or are you trying to do this all in the
SQL Append Statement?

If DCOUNT("*","[YourTempTableName]","[Day] =Year(Date ()),Month(Date()),0)") <
1 Then

'Run your append query

End if

Of course it gets a bit more complex, if your date field is also storing a
time. Since then you have to do something more like your original criteria in
filter section of the DCount.
Thanks for your response, John.

I need at least the last day of the month.

Regards,

Alex

-----Original Message-----
That will tell you if there is at least one record in the
time frame.

To have a "whole" month, do you need at least one record
for every day in the
month? Or at least one record for the 1st day and one
for the last day of the
month? Or exactly one record for every day of the month?

Please define what you mean by a "Whole month".

Alex wrote:

I have a temporary table with dates in the Day column. I
need to delete and download data there from the original
table if there is not whole previous month.

I've created a query (checking whether it's empty) with
the following restriction in criteria for the Day field
to
check it to avoid unnecessary downloading:

DateSerial(Year(Date()),Month(Date())-1,1) And
<DateSerial
(Year(Date()),Month(Date()),1)

Please, advise whether it's correct.

Thanks
.
.
 
Back
Top