Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

dates in SQL-clauses

Posted on 1998-08-03
8
Medium Priority
?
150 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 90 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

670 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