473,698 Members | 2,218 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Date Query problem

Hello.
I have and unbound form with a subform.
The form has 4 controls (a combo, two txt boxes and a button).

The combo has the filter criteria (Equal to, newer than, older than and
between) and the txt boxes are for the data I want to search for.
The textboxes are locked and I have two little buttons that open a
calendar form from where I get the chosen dates.

When I click the (filter) button on the form I can't seem to filter the
records on the subform correctly.

Private Sub FilterBtn_Click ()
Dim frm As Form
Select Case TxtDate1.Value
Case "Select Date ->"
Select Case TxtDate2.Visibl e
Case True:
MsgBox "Please choose valid dates to filter!",
vbExclamation, "Invalid Dates"
Exit Sub
Case False
MsgBox "Please choose a valid date to filter!",
vbExclamation, "Invalid Date"
Exit Sub
End Select
Case Else
Set frm = Form_Report.ord ersPrntSbfrm.Fo rm
Select Case TxtDate2.Visibl e
Case False
Select Case CmbCriteria.Lis tIndex
Case 1:
Case 3:
Case 4:
End Select
Case True
Select Case TxtDate2.Value
Case "Select Date ->"
MsgBox "Please choose a valid second date
to filter!", vbExclamation, "Invalid Date"
Case Else
frm.RecordSourc e = "SELECT
[acc-orders].orderid, acc.kitid, orders.orderdat e, """" AS [Cheque
Number], orders.currcod, currency.curren cy, orders.quantity ,
acc.accnum, IIf([kits].[kitid]=748,[firstname] & "" "" &
[surname],[companyname]) AS [Account Name], kits.desc FROM orders INNER
JOIN (kits INNER JOIN ([currency] INNER JOIN (acc INNER JOIN
[acc-orders] ON acc.accnum = [acc-orders].accnum) ON currency.currco d =
acc.currcod) ON kits.kitid = acc.kitid) ON orders.orderid =
[acc-orders].orderid WHERE ([orders].[orderdate] > " & TxtDate1.Value
& " AND [orders].[orderdate] < " & TxtDate2.Value & ") ORDER BY
acc.kitid, orders.orderdat e;"
End Select
End Select
End Select
End Sub

The txtboxes values are formated as #dd/mm/yyyy#.
If for example I have a record with an order date of the 22/05/2006, if
I choose a date from 18/05/2006 to 25/05/2006 it will show that record,
but if I put 10/05/2006 (or sooner) to 25/05/2006, then subform will be
empty.

Can anyone help me?
Regards,
Luís Torres

May 22 '06 #1
3 1831
Hi Luis,

Try running just the query in the Access Query builder with your
parameters in question and see what results you get. If the query
produces the wrong results (or no results) then your problem is in the
sql.

If the query produces the correct results in the query builder then the
problem is not in the sql. Your form code may not be passing in the
corret parameters to the sql code. To find out where the problem is -
set break points in the form code and step through the code in Debug
mode (you can press the F8 key to step through the code in debug mode -
set a break point first by clicking the left edge of the code moddule
next to any line of code except the titles of subroutines). Then you
can press the F8 key to step through the code. You can place your mouse
over a variable and see the contents of that variable in a message that
will appear right next to the mouse pointer.

hth
Rich

*** Sent via Developersdex http://www.developersdex.com ***
May 22 '06 #2
Hello Rich,

Thankyou for your reply.

I tested the sql code in a query like this:

SELECT [acc-orders].orderid, acc.kitid, orders.orderdat e, "" AS [Cheque
Number], orders.currcod, currency.curren cy, orders.quantity ,
acc.accnum, IIf([kits].[kitid]=748,[firstname] & " " &
[surname],[companyname]) AS [Account Name], kits.desc
FROM orders INNER JOIN (kits INNER JOIN ([currency] INNER JOIN (acc
INNER JOIN [acc-orders] ON acc.accnum = [acc-orders].accnum) ON
currency.currco d = acc.currcod) ON kits.kitid = acc.kitid) ON
orders.orderid = [acc-orders].orderid
WHERE (((orders.order date) Between [Forms]![report]![TxtDate1].[value]
And [Forms]![report]![TxtDate2].[value]))
ORDER BY acc.kitid, orders.orderdat e;

Everything in the query came out perfect but it appears I just can't
seem to put it in the vba code correctly. For what I can see above, the
code sintax is not the same but the references to the objects are
correct.
Any ideas?

Regards,
Luís Torres

May 23 '06 #3
This SQL (yours, as posted):

SELECT [acc-orders].orderid, acc.kitid, orders.orderdat e, "" AS [Cheque
Number], orders.currcod, currency.curren cy, orders.quantity ,
acc.accnum, IIf([kits].[kitid]=748,[firstname] & " " &
[surname],[companyname]) AS [Account Name], kits.desc
FROM orders INNER JOIN (kits INNER JOIN ([currency] INNER JOIN (acc
INNER JOIN [acc-orders] ON acc.accnum = [acc-orders].accnum) ON
currency.currco d = acc.currcod) ON kits.kitid = acc.kitid) ON
orders.orderid = [acc-orders].orderid
WHERE (((orders.order date) Between [Forms]![report]![TxtDate1].[value]
And [Forms]![report]![TxtDate2].[value]))
ORDER BY acc.kitid, orders.orderdat e;

Becomes this when you try to write it in vba:

dim strSQL as strintg
strSQL = "SELECT [acc-orders].orderid, acc.kitid, orders.orderdat e, '' AS
[Cheque
Number], orders.currcod, currency.curren cy, orders.quantity ,
acc.accnum, IIf([kits].[kitid]=748,[firstname] & ' ' &
[surname],[companyname]) AS [Account Name], kits.desc
FROM orders INNER JOIN (kits INNER JOIN ([currency] INNER JOIN (acc
INNER JOIN [acc-orders] ON acc.accnum = [acc-orders].accnum) ON
currency.currco d = acc.currcod) ON kits.kitid = acc.kitid) ON
orders.orderid = [acc-orders].orderid
WHERE (((orders.order date) Between #" & [Forms]![report]![TxtDate1].[value]
& "#
And #" & [Forms]![report]![TxtDate2].[value])) & "#
ORDER BY acc.kitid, orders.orderdat e;"

I have ignored line continuation, but you will have deal with that to spread
the SQL across several lines.

Summary: First replace double quotes with single quotes. Then put a double
quote at beginning and end of SQL string. Then break the references to the
field dates apart so that you can insert the "#" delimiter for the date
fields.

HTH
May 23 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
682739
by: vnl | last post by:
I'm trying to run a SQL query but can't find any records when trying to select a certain date. Here's the sql: SELECT field 1, field2, date_and_time, FROM table1 WHERE date_and_time = '01-SEP-02' I'm getting no results. The date_and_time field is formatted like this: 2002-SEP-02 00:01:04
1
17327
by: Raghu | last post by:
Hello... I am running into a problem while running a query..can some1 help.. this is the query : ************** SELECT * from Table S where S.dtDate1 BETWEEN dateadd(year,1,dateadd(month,-1,getdate())) AND dateadd(day,-1,(dateadd(month,1,dateadd(year,1,dateadd(month,-1,getdate()))))) *************** (first part of the date calculation comes out to be '2005-05-01' and
1
2471
by: Ken | last post by:
I wrote a function to use in queries that takes a date and adds or subtracts a certain length time and then returns the new value. There are times when my function needs to return Null values. Function DateCalc (blah...) As Variant Do Stuff... If Not IsNull(varNewDate) Then DateCalc = varNewDate End If End Function
3
11579
by: Lyn | last post by:
Hi, I am developing a project in which I am checking for records with overlapping start/end dates. Record dates must not overlap date of birth, date of death, be in the future, and must not overlap existing records from the same table. I had this all working some time ago, but recently when I have gone back to do more testing, part of these validations no longer work. While there have been changes to the code in the meantime, I cannot...
2
6513
by: Julie Wardlow | last post by:
Help! I am calculating a future date using the DateAdd function in a query (the calculation also involves an IIf statement), and have managed to get this formula to produce the required result. I then want to search through the records and select those with dates (as caluclated above) within a user defined range, and so I am using a parameter query. However, this query returns dates outside of the range and appears to have particular...
3
6127
by: seegoon | last post by:
Hi to all. I have a small problem I hope someone can help me with. I am running a sql query to a csv file. The query searches for the total of a column between 2 dates. This is a copy of one of the query's: Dim SF_SMT As New OleDb.OleDbCommand("Select count(*) from fault_records.csv where F4 = '" & lblprod.Text & " ' " & " AND F8 AND F1 between #" & SelectproductForm.datestart & "# and #" & Now.Date &
11
5894
by: Dixie | last post by:
How can I programatically, take some Date/Time fields present in a table in the current database and change their type to text? dixie
67
7695
by: PC Datasheet | last post by:
Transaction data is given with date ranges: Beginning End 4/1/06 4/4/06 4/7/06 4/11/06 4/14/06 4/17/06 4/18/06 4/21/06 426/06 4/30/06 I am looking for suggestions on how to find the date ranges where there were no transactions.
10
3268
by: Daniel | last post by:
In Microsoft Access I can write a query that includes the criteria: Between Date()-7 And Date() to retrieve the records from a table that fall within the last week. I'm trying to write a procedure to do this in VB.NET (2005 Express Edition). But I always get the message that the Jet database engine does not recognize the syntax (of the Date function I assume). I've also tried Now() and it works but only by itself. I seem to add or
19
6019
by: phill86 | last post by:
Hi I am re-posting this thread because it has become very confusing and I have got some way to solving the problem so it is a slightly different question from the initial thread. here is the original tread http://bytes.com/topic/access/answers/872005-query-date-range Just to clarify what I am trying to achieve....
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9026
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4366
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.