Solved

Setting a SQL Date parameter in a Where clause

Posted on 2013-06-22
1
550 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

760 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