473,320 Members | 2,054 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Query a date range using a date field from other table

3
I am using MS Access 2007
I have a transaction table which holds all records with posting date on each of them. I used a make table query to find out the max date hold in the transaction table and use the dateAdd function to find the date with 1 month, 5 months and 6 months ago and export it into a table name TRSMPD that only have one record.
I then use the TRSMPD table to query the transaction table to find the records that has dates greater than the value in the 1mth field.

The TRSMPD table structure is
Field Name
Expand|Select|Wrap|Line Numbers
  1. MaxOfPOSTING_DA
  2. 1mth
  3. 5mth
  4. 6mth
with data type Date/Time

I build the following query to find the records but it returns no records
Expand|Select|Wrap|Line Numbers
  1. SELECT Transactions_File.PLANT, Transactions_File.MATERIAL_N, Transactions_File.POSTING_DA, Sum(([QUANTITY_I]*-1)) AS Qty
  2. FROM Transactions_File LEFT JOIN TRSMPD ON Transactions_File.POSTING_DA = TRSMPD.MaxOfPOSTING_DA
  3. WHERE (((Transactions_File.PLANT) Like "DC*") AND ((Transactions_File.POSTING_DA)>[TRSMPD]![1mth]))
  4. GROUP BY Transactions_File.PLANT, Transactions_File.MATERIAL_N, Transactions_File.POSTING_DA;
I have test it with a date value to replace the 1mth field name as criterna and it works.
It also works with input field for date criteria
I also tried using DateSerial and Format function in the criteria and Access gives me error message telling data type mismatch
When I use CDate function, Access error message tells Invalid use of Null

I want to make this query fully automatic that will update when new records are added and does not require any manual input when the query runs. Please advise.
Mar 26 '09 #1
7 3458
ChipR
1,287 Expert 1GB
Try replacing [TRSMPD]![1mth] (you just can't do that) with:
(SELECT MAX(1mth) FROM TRSMPD)
Mar 26 '09 #2
NeoPa
32,556 Expert Mod 16PB
If you have a single record in the table of a global nature (IE. That record pertains to all data), then there is no need for a JOIN in your FROM clause. You simply need to separate the two tables with a comma (,).
Mar 26 '09 #3
NeoPa
32,556 Expert Mod 16PB
I suspect the shriek (!) character may cause a problem, but you would want to use [TRSMPD].[1mth].
Mar 26 '09 #4
nhkam
3
Hi ChipR,
The query give me a syntex error message when using the code you suggest.
By the way the TRSMPD table only have one record, so, I don't understand why I need to use max function.
Mar 26 '09 #5
nhkam
3
Hi NeoPa,

All I need to get is a list of records from transaction file that has the posting date from the most current date backward to one month ago in the record. eg. most current date in record is March 15, 2009, then I need to list all records that is greater than February 15, 2009.

I change the shriek to dot but still not getting any record from the query.
Any other way I can try ?
Mar 26 '09 #6
NeoPa
32,556 Expert Mod 16PB
Did you read my post #3?
Mar 26 '09 #7
OldBirdman
675 512MB
I want to make this query fully automatic that will update when new records are added and does not require any manual input when the query runs. Please advise.
The following logic would do as requested without the need for a table for the newest date.
Expand|Select|Wrap|Line Numbers
  1. Dim dteNewest As Date
  2. Dim dte1Ago As Date
  3. Dim dte5Ago As Date
  4.  
  5. dteNewest = DMax(...
  6. dte1Ago = DateAdd("m", -1, dteNewest)
  7. dte5Ago = ...
  8.  
  9. strWHERE = "WHERE (((Transactions_File.PLANT) Like 'DC*'  AND ((Transactions_File.POSTING_DA)>" & dte1Ago & ")) " 
  10.  
  11. strSQL = strSELECT & strFROM & strWHERE & strGROUPBY 
Mar 26 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Russell | last post by:
I'm having a fit with a query for a range of dates. The dates are being returned from a view. The table/field that they are being selected from stores them as varchar and that same field also...
4
by: Akinia | last post by:
Hi every body I've a little problem with my query, I can't figure it out. I've three tables: Table A (EmployeNr, Date, Code) Table B (EmployeNr, Date, Code) Which is an historic of Table A...
3
by: rrh | last post by:
I am trying to update a field in one table with data from another table. The problem I'm running into is I need to base the update on a range of data in the 2nd table. Table 1 has: date field...
4
by: C White | last post by:
Hi I am having problems with running a query that does the following there are 5 fields in a table that the query is based on, the first four are simple enough and all that happens is that the...
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
3
by: Don Sealer | last post by:
I'm guessing this is pretty simple however not simple enough for me. I'm developing a database to track expenses, income, banking transactions, etc. I have a very simple query with four fields,...
1
by: flumpuk | last post by:
Hi My job currently requires me to enter data from 300+ forms a month. The system which we used in Excel was slow , and theprevious guy had three workbooks for this job . I have created...
5
by: jennwilson | last post by:
Using Access 2000 - I have a query that is suppose to return the records from table within specified time range and find matching data from another table . Table houses Clinician name, location...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.