Solved

dates in SQL-clauses

Posted on 1998-08-03
8
146 Views
Last Modified: 2010-05-03
I have dBase IV database where is date field and date format is like this: 20.7.1998 (day.month.year).

Then I have Data component and I wanna set components RecordSource property in a runtime. I tryed this but this isn't working.
Data1.RecordSource = "SELECT * FROM " + myDB + " WHERE Date >= #24.7.1998# AND Date <= #24.7.1998#"

Why this isn't working? Could you give me an example?

How I set it if those Dates are variables?

Thanks in advance!
0
Comment
Question by:majala
8 Comments
 
LVL 14

Expert Comment

by:waty
ID: 1467565
Did you tried your SQL like this :

Data1.RecordSource = "SELECT * FROM " + myDB + " WHERE Date >= #24/7/1998# AND Date <= #24/7/1998#"

/ instead of . between day,month, year.
0
 

Expert Comment

by:vinoopauls
ID: 1467566
Try this:

Data1.RecordSource = "SELECT * FROM  tablename  WHERE Date >= ' 24/7/1998' AND
      Date <= '24/7/1998' " 

Data1.RecordSource ="SELECT * FROM  tablename  WHERE Date >= ' " & datevar1 &" '                                   AND  Date <= ' " & datevar2 &" ' "

The datatype in the database should be date and the format being sent should match.
Also your system date format should match the database.
0
 

Expert Comment

by:jaimereed
ID: 1467567
When you set a record source property you must use valid Jet SQL syntax (similar to ANSI). For dates this means that you must use the American "mm/dd/yy" format. You must rephrase your date using something like:

dim d as date
d= THEDATEINQUESTION
Data1.RecordSource = ".....#" + Format("mm/dd/yy", d) +"#..."

You can avoid this by specifying the month as a string Jan/Feb/etc.

You should try to avoid periods (although you can use them with Format() if the Windows country settings are set correctly). The database engine will provide the neccessary conversion to the format of your database.
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:majala
ID: 1467568
Vinoopauls: Answer you gave didn't work. I guess there's nothing wrong in your answer (I didn't got any errors when I ran my program) but I think that I have to use those #-marks if play with dates?

That comment given by WATY did work. If you send your answer as a question then I will grade your answer. Would you at a same time give me an example how to do if those dates are variables?
0
 
LVL 14

Accepted Solution

by:
waty earned 30 total points
ID: 1467569
Did you tried your SQL like this :

Data1.RecordSource = "SELECT * FROM " + myDB + " WHERE (Date >= #" & Format("DD/MM/YYYY", yourDate1)& ") AND (Date <= #" & Format("DD/MM/YYYY", yourDate2) & "#)"

0
 

Author Comment

by:majala
ID: 1467570
Actually I got it work without those format-clauses:

criteria = "SELECT * FROM " + myDB + " WHERE Date >=#" + myDate1 + "# AND Date <= #" + myDate2 + "#"

0
 
LVL 14

Expert Comment

by:waty
ID: 1467571
It is quite usefule to use the format when you users coming from different countries (like I have here) and having different date format
0
 
LVL 14

Expert Comment

by:waty
ID: 1467572
It is quite usefule to use the format when you users coming from different countries (like I have here) and having different date format
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

808 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