Selecting A single Month From a Table with Multiple Months

The following code is used as the criteria in a selct query for a date field:

>=DateSerial(Year(Date()),Month(Date())-1,1) And <=DateSerial(Year(Date()),Month(Date()),0)

It has worked fine until the table included records from January 2010, 
database was created in 2009.  Is there a fix or a better way to accomplish 
the intent?


0
Utf
2/3/2010 8:06:01 PM
access 16762 articles. 3 followers. Follow

5 Replies
1028 Views

Similar Articles

[PageSpeed] 44

Not sure what your problem is the expressions you have return the first and 
last day of the prior month.  So this is February 3, 2010 and the expression 
return 1/1/2010 and 1/31/2010.

What do you want returned?  What is the problem you are having?

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

shane wrote:
> The following code is used as the criteria in a selct query for a date field:
> 
>> =DateSerial(Year(Date()),Month(Date())-1,1) And <=DateSerial(Year(Date()),Month(Date()),0)
> 
> It has worked fine until the table included records from January 2010, 
> database was created in 2009.  Is there a fix or a better way to accomplish 
> the intent?
> 
> 
0
John
2/3/2010 8:24:53 PM
On Wed, 3 Feb 2010 12:06:01 -0800, shane <shane@discussions.microsoft.com>
wrote:

>The following code is used as the criteria in a selct query for a date field:
>
>>=DateSerial(Year(Date()),Month(Date())-1,1) And <=DateSerial(Year(Date()),Month(Date()),0)
>
>It has worked fine until the table included records from January 2010, 
>database was created in 2009.  Is there a fix or a better way to accomplish 
>the intent?
>

What specific problem did you have? what records did you see that you didn't
want, or vice versa?

As written, if you ran it today, it would retrieve records for January 2010;
if you had run it during January, it would retrieve records for December 2009.
Is that not what you're seeing?
-- 

             John W. Vinson [MVP]
0
John
2/3/2010 11:23:08 PM
Shane -

The problem would always occur when the current date is in January, because 
you were keeping the Year of the date the same in the first part of the 
criteria.  This would have produced the criteria  >= 12/1/10 AND <= 12/31/09, 
which would always be false.  Try this instead, which subtracts a month from 
the first of the current month:

>= DateAdd("m", -1, DateSerial(Year(Date()), Month(Date()), 1)) And <=DateSerial(Year(Date()),Month(Date()),0)

-- 
Daryl S


"shane" wrote:

> The following code is used as the criteria in a selct query for a date field:
> 
> >=DateSerial(Year(Date()),Month(Date())-1,1) And <=DateSerial(Year(Date()),Month(Date()),0)
> 
> It has worked fine until the table included records from January 2010, 
> database was created in 2009.  Is there a fix or a better way to accomplish 
> the intent?
> 
> 
0
Utf
2/4/2010 3:06:05 PM
Daryl,

DateSerial adjusts correctly.

For instance,
DateSerial(2010,1-1,1) returns December 1 2009.

The expressions as posted work to give you the begin and end date of the month 
prior to the current month.

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

Daryl S wrote:
> Shane -
> 
> The problem would always occur when the current date is in January, because 
> you were keeping the Year of the date the same in the first part of the 
> criteria.  This would have produced the criteria  >= 12/1/10 AND <= 12/31/09, 
> which would always be false.  Try this instead, which subtracts a month from 
> the first of the current month:
> 
>> = DateAdd("m", -1, DateSerial(Year(Date()), Month(Date()), 1)) And <=DateSerial(Year(Date()),Month(Date()),0)
> 
0
John
2/4/2010 4:14:07 PM
John -

My bad.  I was focused on the year, even though I know the zeros are handled 
properly.

I don't know why this wouldn't work...

-- 
Daryl S


"John Spencer" wrote:

> Daryl,
> 
> DateSerial adjusts correctly.
> 
> For instance,
> DateSerial(2010,1-1,1) returns December 1 2009.
> 
> The expressions as posted work to give you the begin and end date of the month 
> prior to the current month.
> 
> John Spencer
> Access MVP 2002-2005, 2007-2010
> The Hilltop Institute
> University of Maryland Baltimore County
> 
> Daryl S wrote:
> > Shane -
> > 
> > The problem would always occur when the current date is in January, because 
> > you were keeping the Year of the date the same in the first part of the 
> > criteria.  This would have produced the criteria  >= 12/1/10 AND <= 12/31/09, 
> > which would always be false.  Try this instead, which subtracts a month from 
> > the first of the current month:
> > 
> >> = DateAdd("m", -1, DateSerial(Year(Date()), Month(Date()), 1)) And <=DateSerial(Year(Date()),Month(Date()),0)
> > 
> .
> 
0
Utf
2/4/2010 6:18:01 PM
Reply:

Similar Artilces:

Auto Accept won't work for single resource
Hi, I have about 25 "resources" in my org and they all work fine through the auto accept script. Today, I'd like to add a resource that completely allows for duplicate entries into the calendar. I thought this would do it but it seems that I am still getting denied when overlaps in scheduling occur. I'd just like this resource to accept everything (yes, even overlapping appointments). I've checked all of the addressing and everything is correct and gone through what the global vs. mailbox settings are and I beilieve I've captured everything. Here is my X...

Combo box list selection based on earlier selection by user
HI, I have a form that has a combo box 1 (Product) that reads a the Product table and has a unique id attached to each product (RO#). There is a second combo box 2 that is RO#. Now what I would like to do is when a user selects a Product in combo box 1, the system should lookup the Product selected from combo box 1 and upload the corresponding RO# in the combo box 2 list. Now I am using both combo boxes as Unbound and in the combo box 2 I have the two columns Product and RO# - in the Criteria row of RO# I have the following: Like IIf([Forms]![xa_f_lookup]![RO#]=" ",[Forms]![x...

Run report on multi selected records.
I try to make a report for a custom entity that works like the Account Summary: let's say that it's Customer's Inquiry Summary for entity Customer's Inquiry I made the report so that I'm able to run the report on Customer's Inquiry Form. But when I select multi records in the list of Customer's Inquiry and run report, only one record is show in one page of the the report. I would like to have the selected records appear in the report with each record on each page. How can I do this? ...

Multiple copies of messages, sent as attachments
I've been getting an error once and a while using outlook. It seems that some of my emails are duplicating themselves, and my friends/co workers get up to 98 messages from me, when I've on.y sent one. IT appears normal, but as if they have an attachement, even if there wasn't originally an attachment. HELP!! Thanks ...

Pivot Table Data
This is a multipart message in MIME format. --=_alternative 006B899F86256E2F_= Content-Type: text/plain; charset="us-ascii" I have a file that contains pivot tables along with some buttons and macros to change the way the pivot table looks depending on what type of information that you would like to view. The pivot table is based on data on a separate worksheet but is within the same workbook (separate tabs). If I change my data source (i.e. I change the names of individuals to new names) and refresh my pivot table, the information changes like I want it to. However, if I de...

Comparative sales reports by day, week, month and year
Is there a way to program comparative sales report by time period using Active Reports or must I use Crystal Reports? An example is a sales report comparing sales for two months; two seperate columns with each column displaying the sales figures for requested months. ...

Can't select objects in Excel 2007
I'm trying to create a form in Excel 2007, and although I can manipulate, copy & paste controls (check boxes, etc) I can't select multiple objects to align them, etc. I've checked on-line help (and have followed the instructions), and other websites, but no one seems to have indicated a problem. It is extremely cumbersome and I need a solution. Any ideas? Thanks in advance, Jim Berglund I know this is about a year too late, but it may help others who have stumbled across this page looking for similar help. On the Home tab, in the Editing group, click Find & Select....

Function to multiple ranges
Which function may be used with multiple ranges? Commonly used "lookups", "index" and "match" don't seem to work. Is there a trick in multiple ranges? Tomek Polak Some functions work, others don't. INDEX has a 4th argument that allows you to specify the area (which of the multiple ranges). The lookup and match functions require a single contiguous block of cells. On Wed, 29 Oct 2003 14:19:08 +0100, "Tomek" <tpolak@poczta.onet.pl> wrote: >Which function may be used with multiple ranges? > >Commonly used "lookups",...

Vertical line on column chart with monthly data
I am attempting to add a vertical line to a dynamic column chart. I've followed the steps described by Jon Peltier at http://peltiertech.com/Excel/Charts/AddLineVertSeries.html This procedure works fine until I change the base unit on the x-axis to "Days." This causes the columns to turn into vertical lines (since each monthly observation is really for, e.g., 6/1/2007). If I leave the x-axis as monthly and then add the secondary x-axis for the vertical (xy scatter) line, the scale on the secondary x-axis goes from 1/1/1900 - 12/1/2036, which shoves my vertical line far t...

automatically update chart plotting current month and previous 6
I need to automatically update a chart every month for a report but I only want to plot the current month and six months back each time. For example Feb-Aug for the Aug report then for the Sept report plot Mar-Sept. Any suggestions? This example shows how to plot the last 12 months. Perhaps you can adapt it to cover the last 7 months: http://peltiertech.com/Excel/Charts/DynamicLast12.html - Jon ------- Jon Peltier, Microsoft Excel MVP Peltier Technical Services Tutorials and Custom Solutions http://PeltierTech.com/ _______ Jane wrote: > I need to automatically update a chart ev...

Workbook pivot table design function
I used Sheet1 as the data source to create a pivot table in a new worksheet which I named Sheet PT. Is it possible to design the workbook so that I can delete the data in Sheet1 and then paste new data with more or less rows in Sheet1 and have the pivot table in Sheet PT update to reflect the new data that has been pasted into Sheet1 but the formating of the pivot table stays the same? One thought is to simply set the pivot's source range (In step 2 of the PT wizard) to cover the max expected extent of source data at the onset, then configure the base PT format. Then jus...

Lot Selection not Showing when I select PO on Receiving Entry
Usually, the Lot selection screen would pop up when I select a PO at the Line Detail of the Receivings Entry, now it does not! And GP will let items post without a lot number! It seems as if a setting has changed. Any ideas anyone? Any help is appreciated. Thanks, R Are you sure the item is marked to track lots? This wiould be set item by item on the Item Maintenance Options window. -- Richard L. Whaley Author / Consultant / MVP 2006-2008 Documentation for Software Users Get our Free Tips and Tricks Newsletter and check out our books at http://www.AccoladePublications.com &q...

Multiple Attributes
I have created a custom Entity - "Inventory" This has a relationship with Accounts which is used to show the location of a piece of hardware - a lookup field is used to choose an account. All good. However I'd also like to have a couple of other lookups for Supplier and Manufacturer. These are both stored in Accounts so they'd need to reference an entry in Accounts again. Is this possible? I know you cannot create multiple relationships between entities but can you create multiple attributes using the one relationship? Can anyone help with this - still got no further.....

filling a control in a continuous form with a field from a table
I had posted this under "Access Reports" in error and received a response and responded. Please follow the dialog for an explaination of my question: Original Question: I have a form with the fields: date, client, atty, time, billable and description. All these fields update the Time Sheet Table. I want the atty field to automatically take the attorney's name from the table Attorney which contains one field called Atty. So for I can only figure out how to use a combo box to chose the Attorney table field. Response Received: Your combo box to select the at...

Select contact then hangs
Hi, please help. I have a user that when she selects a contact using To: in a new email, after selecting 2, it closes outlook??. Spec is W2kSP4\office2k with all windows updates and office updates installed. Profile has been deleted and re-created, plus i have set up personal folders and moved contacts into there, and set that folder as a default, but makes no difference. Please help. ...

Selecting rows from various sheets
Hi all, I have several sheets with a few columns in each. One colum in each sheet has a unique value. Most of these unique values are th same in each sheet but not all. Is there any way that I can set up new sheet that will have the unique value in column 1 and th corresponding column values frommeach sheet beside it. For example Sheet 1 aa 1 1 1 bb 2 2 2 cc 3 3 3 Sheet 2 aa 4 4 cc 5 5 Result aa 1 1 1 4 4 bb 2 2 2 cc 3 3 3 5 5 Thanks alot, Sha -- sha ----------------------------------------------------------------------- shav's Profile: http...

Excel 2000
I used to have this option by right clicking and selecting split. However i don't have it now. I had it on WIN2000 and now I have XP proffesional Hi not possible in Excel -- Regards Frank Kabel Frankfurt, Germany "Roy S" <Roy S@discussions.microsoft.com> schrieb im Newsbeitrag news:BE9E61EA-466E-4391-8400-5967977E9325@microsoft.com... > I used to have this option by right clicking and selecting split. However i > don't have it now. I had it on WIN2000 and now I have XP proffesional I bet you're thinking about a table in MSWord???? Roy S wrote: > &g...

select text in Calendar
I'm working on a calendar in Publisher. I'm adding text into a cell by spacing down 1 point, then typing in 8 points. Doing fine until April. At that time, I can only select cells (whole days). It will not let me select the text. Help is no help. Any hints out there. Did I accidentally select something to do this? Bonnie Have you added a picture to the cell or a shape? If you have send it to the back, make the cell no fill and try again. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "GoBonnieGo" <GoB...

Inserting ID Number from Another Table
Hello, I have two tables. One stores "employee information" and another stores "time sheet information" for all the employees. The "Employees" table has a unique identifier for each employee (EmployeeID). The "Time Sheet" table also has a unique identifier for each time sheet entry (TimeSheetID). When the data entry person inputs time sheet information onto the "TimeSheet" table, she selects the employee from a combo box which combines the first and last name of the employee from the employee table. What I want to do is automatically inse...

multiple V-lookup
I have a worksheet that has multiple rows that have the same name. For example. I have a worksheet that looks like this Name 401k FICA Julie 100 200 Patrick 200 400 Sam 50 100 Julie 100 200 Julie 100 200 Patrick 200 400 I am trying to figure out how I can have excel look at the worksheet and find all entries labed Patrick and return the columns already summed. Similar to a vlookup but able to know that if I want the 401k column it should return ...

How do I project monthly income in Excel?
If I want to project my income or cost for Nov. or Dec. and have values in the other months, how can I project what my income or cost would be for November or December based on the other months? A lot of this depends on the nature of your income and / or expenses, which may change from month to month. For instance, your heating expense bill will increase in winter and decrease in summer. Your summer vacation expenses go up in summer (duh) and decrease in winter. When I have to do this work I try to base it on the key drivers for the particular expense. For instance, in a previous life ...

macro to filter data based on selected data
Hi, I am looking for a macro that requests input of a reference code and then a date and then filters the data in my spreadsheet based on this criteria. I am using excel 2007. Any help with this will be greatly appreciated. You can probably record a macro while doing it manually and then clean it up and add input boxes to ask the question or input your variable in a cell and use that. If all else fails, If desired, send your file to my address below. I will only look if: 1. You send a copy of this message on an inserted sheet 2. You give me the newsgroup and the ...

Link select with a blast
I have Win 7 Home Premium, x64. Quite often, when I select a link, a mouse pointer changes to a palm with a blast. I understand, the palm is the standard mouse pointer for link select, but what is the blast? What it indicates? -- Ilya Zeldes Fort Myers, Florida Hi Ilya, I suspect that this is being caused by a tracking program. Run something like Ad-Aware and see if it indicates a tracking company. If so, you can delete it, however, it might prevent you from accessing that particular website. Dave "Ilya Zeldes" wrote in message news:7A6FF9B1-5512-44...

Select Case in a Change Event
Hi, I am trying to use a worksheet Change Event to trap changes to specific columns. depending on which column is chnaged by the user, the value in another ciolumn will be altered; so, changes in either column O or P will update column Q, changes in either column T or U will update column V and changes in column Z or AA will update column AB. What I can't figure out is the Select Case bit (where I've got the shouted question below). Here's what I've put together, any comments would be much appreciated. Private Sub Worksheet_Change(ByVal Target As Range) ...

how to backup Single Mailbox
i need help im using backup exec 9.0,i wanna backup Single Mailbox ,how to do that. thanks Use exmerge and save it to pst. -- Sincerely, D�j� Ak�m�l�f�, MCSE MCSA MCP+I www.akomolafe.com www.iyaburo.com Do you now realize that Today is the Tomorrow you were worried about Yesterday? -anon "ayaz" <anonymous@discussions.microsoft.com> wrote in message news:16f3101c4181d$2b5d0090$a301280a@phx.gbl... > i need help > im using backup exec 9.0,i wanna backup Single > Mailbox ,how to do that. > thanks > ...