Results 1 to 6 of 6
  1. #1
    stevesa is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2020
    Posts
    2

    Queries and Dates

    Hi,

    Microsoft Access 2003 Front-End with SQL Server Backend


    I have the following query that is run from a reports form. On the form is 2 fields for the StartDate and EndDate which opens a report.
    This is was working for years and now has suddenly been stalling and causes an ODBC timeout.

    I can run the query if i just put the following in the criteria Between #01/01/1998# And #16/03/2020# but when I use this query behind the form it just stalls or ODBC timeout

    If put the following in the criteria on the query "Between [Forms]![Reports]![StartDate] And [Forms]![Reports]![EndDate] the query also stalls.

    INSERT INTO [Collate TX Temp] ( CompanyID, Name, SumOfTX, TransTypeID, SumOfEuroTX )
    SELECT Companies.CompanyID, Companies.Name, Sum((([Amount]*[VatRate]/100)+[Amount])) AS Gross, "13 Sales Invoice" AS [TX Type], Sum((([EuroAmount]*[VatRate]/100)+[EuroAmount])) AS EuroGross
    FROM Jobs INNER JOIN ((Customers INNER JOIN (Companies INNER JOIN [Sales Invoices] ON Companies.CompanyID = [Sales Invoices].CompanyID) ON Customers.CustomerID = [Sales Invoices].CustomerID) INNER JOIN [Sales Invoice Details] ON [Sales Invoices].SalesInvoiceID = [Sales Invoice Details].SalesInvoiceID) ON Jobs.JobID = [Sales Invoice Details].JobID
    WHERE ((([Sales Invoices].SalesInvoiceDate) Between [Forms]![Reports]![StartDate] And [Forms]![Reports]![EndDate]))
    GROUP BY Companies.CompanyID, Companies.Name, [Sales Invoices].SalesInvoiceID, [Sales Invoice Details].VatRate
    ORDER BY [Sales Invoices].SalesInvoiceID;

    Any help would be greatly appreciated

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    if the date field also has time it could stop working. remove the time in the query.
    Some ODBC will convert the date to string and again the dates wont work.
    convert the date/time field to date only:

    DteFld: format([dateField],"mm/dd/yyyy")

    then you must use zero fill full months & days format: 03/01/2020
    then the dates work.

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    It looks like you are using non-US date format for the dates:
    Between #01/01/1998# And #16/03/2020# (Between 01 January, 1998# And 16 March ,2020)

    On the form, try entering the dates in the controls in US format:
    Code:
     Between #01/01/1998# And #03/16/2020#  
    (Between January 01,1998 And March 16,2020)
    then open the report.


    See the article by Allan Browne International Dates in Access

    I have used the function in Paragraph #3 to convert the date format.

    On the form, have 2 more unbound text controls. In the after update event of the two date controls, [Forms]![Reports]![StartDate] And [Forms]![Reports]![EndDate], have code to call the Function SQLDate and put the converted date into the new DateStart and DateEnd control. Reference the two new text date controls in the query.


    If I wasn't clear, let me know.....

  4. #4
    stevesa is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2020
    Posts
    2
    Quote Originally Posted by ranman256 View Post
    if the date field also has time it could stop working. remove the time in the query.
    Some ODBC will convert the date to string and again the dates wont work.
    convert the date/time field to date only:

    DteFld: format([dateField],"mm/dd/yyyy")

    then you must use zero fill full months & days format: 03/01/2020
    then the dates work.

    ranman256 date field has no time but what I did was copy the 2 tables, Sales Invoices and Sales Invoices Details tables and made them local to my Frontend instead of a linking to the SQL Server. I ran the query again with the criteria "Between [Forms]![Reports]![StartDate] And [Forms]![Reports]![EndDate]" and this works fine no issue..

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    What ODBC driver do you use to connect to your SQL back-end? If using the generic "SQL Driver" that comes with Windows try to replace it with ODBC Driver 17 for SQL Server and see if it works.
    https://docs.microsoft.com/en-us/sql...l-server-ver15
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    Bullschmidt's Avatar
    Bullschmidt is offline Freelance DB Developer
    Windows 10 Office 365
    Join Date
    Mar 2020
    Location
    USA
    Posts
    64
    And for dates with SQL Server you don't use the # before and after each date (such as in Microsoft Access) but rather treat as regular text such as:

    Code:
     SELECT * FROM Orders WHERE OrderDate='2008-11-11'
     
    as shown in this article:

    https://www.w3schools.com/sql/sql_dates.asp





Please reply to this thread with any new information or opinions.

Similar Threads

  1. Queries - With Dates as headers
    By kamathmanoj in forum Access
    Replies: 2
    Last Post: 08-22-2019, 05:45 AM
  2. Dates and queries
    By JQuinnC in forum Queries
    Replies: 3
    Last Post: 04-14-2016, 10:45 AM
  3. Dates, Forms, and Queries
    By Ace2014 in forum Access
    Replies: 21
    Last Post: 06-18-2014, 06:01 AM
  4. Subtracting Dates in Queries
    By seanpbent in forum Access
    Replies: 1
    Last Post: 02-01-2013, 04:28 PM
  5. Handling dates in queries
    By mrk68 in forum Access
    Replies: 4
    Last Post: 03-23-2009, 06:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums