Solved

Setting a SQL Date parameter in a Where clause

Posted on 2013-06-22
1
551 Views
Last Modified: 2013-06-22
I am creating a VBA Access SQL statement to use two stored date variables to create a where clause parameter.

Can someone help me with the syntax?

Here is the code snippet.

If Month(Date) = 1 Then
        DateTo = Format((DateSerial(Year(Date), 1, 1) - 1), "mm/dd/yyyy")
        DateFrom = Format(DateSerial(Year(Date) - 1, 12, 1), "mm/dd/yyyy")
    Else
        DateTo = Format(DateSerial(Year(Date), Month(Date), 1) - 1, "mm/dd/yyyy")
        DateFrom = Format(DateSerial(Year(Date), Month(Date) - 1, 1), "mm/dd/yyyy")
    End If


          "WHERE (((dbo_BarBillsProration.InsuranceOrderID)='1') AND ((dbo_BarBills.Status)='POSTED') AND ((dbo_BarBills.Type)='FINAL') AND " & _
          "((dbo_BarBills.EffectiveDateTime) Between " & DateTo & "And " & DateFrom & ")) " &


Thanks

Glen
 _
0
Comment
Question by:GPSPOW
1 Comment
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 39268480
All you need is this:

    DateTo = Format(DateSerial(Year(Date), Month(Date), 0), "\#mm\/dd\/yyyy\#")
    DateFrom = Format(DateSerial(Year(Date), Month(Date) - 1, 1), "\#mm\/dd/\yyyy\#")

regardless of the month.

/gustav
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now