Solved

dates in SQL-clauses

Posted on 1998-08-03
8
143 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
 

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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

708 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

16 Experts available now in Live!

Get 1:1 Help Now