Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to determine date range 2

Status
Not open for further replies.

MemphisVBA

Technical User
Joined
May 31, 2006
Messages
23
Location
US
Hello -
I have an app that imports a spreadsheet in to a table - I need help with a query that will tell me the date range of the records. Is there an easy way to get the minimum and maximum date values?

Thanks
 
Thanks! That worked perfectly
 
How can I use these min/max values to query a different table?

I modified your query example to save the dates in a table (which would have only 1 record) - I thought I could use a Dlookup to get the dates, but I get a type mismatch error:

Code:
SELECT tblInvoice.InvoiceNo, tblInvoice.InvDate
FROM tblInvoice, tblDateRange
WHERE (((tblInvoice.InvDate) Between DLookUp([tblDateRange]![StartDate],"tblDateRange",[tblDateRange]![DateID]=1) And DLookUp([tblDateRange]![EndDate],"tblDateRange",[tblDateRange]![DateID]=1)));

Is there a better (correct) way
 
SELECT tblInvoice.InvoiceNo, tblInvoice.InvDate
FROM tblInvoice, tblDateRange
WHERE tblInvoice.InvDate Between tblDateRange.StartDate And tblDateRange.EndDate AND tblDateRange.DateID = 1

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks PVH - but I am still getting an Error:
"Data type mismatch in criteria expression" - I'll keep plugging away it it, but any suggestions would be greatly appreciated.
 
I got it to work by removing the "=1" part
Code:
SELECT tblInvoice.InvoiceNo, tblInvoice.InvDate
FROM tblInvoice, tblDateRange
WHERE tblInvoice.InvDate Between tblDateRange.StartDate And tblDateRange.EndDate

Thanks Again
 
AND tblDateRange.DateID = [!]'[/!]1[!]'[/!]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Question:

I am trying to query a table (tblInvoice) based on the Min and Max dates of records in another table (ImportTable)

I need to temporarily save the dates for later use, so I have them in a table (tblDateRange)

With help (see previous posts above) I was able to come up with this to save the start and end dates (this works fine)
Code:
    MySQL = "INSERT INTO tblDateRange ( StartDate, EndDate ) " & _
            "SELECT Min(ImportTable.InvDate) AS StartDate, Max(ImportTable.InvDate) AS EndDate " & _
            "FROM ImportTable;"
    DoCmd.RunSQL MySQL


Below is my problem:

I have the code below that uses the dates saved in the table above, but it doesn't return any records - what am I doing wrong here?


Code:
SELECT tblInvoice.InvoiceNo, tblInvoice.InvDate, tblInvoice.PartNo
FROM tblInvoice, tblDateRange
WHERE (((tblInvoice.InvDate) Between DLookUp([tblDateRange]![StartDate],"tblDateRange",[tblDateRange]![DateID]='1') And DLookUp([tblDateRange]![EndDate],"tblDateRange",[tblDateRange]![DateID]='1')));

Thanks
 
I was able to get it working by making this change to the SQL:

Code:
Between DLookUp("[tblDateRange]![StartDate]","[tblDateRange]","[tblDateRange]![DateID]='1'") And DLookUp("[tblDateRange]![EndDate]","[tblDateRange]","[tblDateRange]![DateID]='1'")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top