A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Update query with date criteria



 
 
Thread Tools Display Modes
  #1  
Old December 9th, 2009, 04:35 PM posted to microsoft.public.access.queries
gillah11
external usenet poster
 
Posts: 8
Default Update query with date criteria

Hi all. I have an update query that should only update a record if today
falls between the 1st of it's month and the 7th of the following month. For
instance, if the record date is 11/15/2009, it should only update if today is
between 11/1/2009 and 12/7/2009, or if the record date is 10/6/2009 is should
only update if today is between 10/1/2009 and 11/7/2009. Here's the criteria
I was trying to use, and I was using this criteria in the field that I want
to update if the criteria is true:

now()dateserial(year[ticketcreateddate],month[ticketcreateddate]+1,7)

Using this, I'm only getting updates on the records created on 12/7/2009.

Any other ideas?
  #2  
Old December 9th, 2009, 05:16 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default Update query with date criteria

It would help if you posted the SQL of the query you are trying to use.
(Hint - Menu: View : SQL)

PERHAPS the following will give you the idea. I'm cannot tell from your post
what field you are attempting to update and what field you are using to
determine criteria and whether you are attempting to update more than one field.

UPDATE [YourTable]
SET [Some Field] = ??????
WHERE [Record Date Field] Between DateSerial(Year(Date()),Month(Date()),1)
and DateSerial(Year(Date()),Month(Date())+1,7)

The Where condition above identifies which records to update.



John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

gillah11 wrote:
Hi all. I have an update query that should only update a record if today
falls between the 1st of it's month and the 7th of the following month. For
instance, if the record date is 11/15/2009, it should only update if today is
between 11/1/2009 and 12/7/2009, or if the record date is 10/6/2009 is should
only update if today is between 10/1/2009 and 11/7/2009. Here's the criteria
I was trying to use, and I was using this criteria in the field that I want
to update if the criteria is true:

now()dateserial(year[ticketcreateddate],month[ticketcreateddate]+1,7)

Using this, I'm only getting updates on the records created on 12/7/2009.

Any other ideas?

  #3  
Old December 9th, 2009, 07:56 PM posted to microsoft.public.access.queries
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default Update query with date criteria

Try this --
WHERE Date() Between DateSerial(Year([ticketcreateddate]),
Month([ticketcreateddate]), 1) AND DateAdd("m", 1,
DateSerial(Year([ticketcreateddate]), Month([ticketcreateddate]), 7))

Or in design view add calculated field like this --
MyDate: Date()
Criteria --
Between DateSerial(Year([ticketcreateddate]), Month([ticketcreateddate]),
1) AND DateAdd("m", 1, DateSerial(Year([ticketcreateddate]),
Month([ticketcreateddate]), 7))

--
Build a little, test a little.


"gillah11" wrote:

Hi all. I have an update query that should only update a record if today
falls between the 1st of it's month and the 7th of the following month. For
instance, if the record date is 11/15/2009, it should only update if today is
between 11/1/2009 and 12/7/2009, or if the record date is 10/6/2009 is should
only update if today is between 10/1/2009 and 11/7/2009. Here's the criteria
I was trying to use, and I was using this criteria in the field that I want
to update if the criteria is true:

now()dateserial(year[ticketcreateddate],month[ticketcreateddate]+1,7)

Using this, I'm only getting updates on the records created on 12/7/2009.

Any other ideas?

  #4  
Old December 9th, 2009, 08:06 PM posted to microsoft.public.access.queries
Jerry Whittle
external usenet poster
 
Posts: 4,732
Default Update query with date criteria

I think that you need a Between statement. The first part sets the date to
the first of the month. The part after AND add a month and just under 8 days
to that value. That way if records have a time component, It will still
select records up to a second before the 8th.

Between Date() - Day(Date()-1) AND DateAdd("m",1,Date() - Day(Date())+7.99999)

PS. I bet that there is a nicer way of doing it that all my Date()s.
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


"gillah11" wrote:

Hi all. I have an update query that should only update a record if today
falls between the 1st of it's month and the 7th of the following month. For
instance, if the record date is 11/15/2009, it should only update if today is
between 11/1/2009 and 12/7/2009, or if the record date is 10/6/2009 is should
only update if today is between 10/1/2009 and 11/7/2009. Here's the criteria
I was trying to use, and I was using this criteria in the field that I want
to update if the criteria is true:

now()dateserial(year[ticketcreateddate],month[ticketcreateddate]+1,7)

Using this, I'm only getting updates on the records created on 12/7/2009.

Any other ideas?

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 01:24 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.