Solved

dates in SQL-clauses

Posted on 1998-08-03
8
148 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error when passing an argument to a vb6 that contains  '/' 7 49
checkbox to hide entire section 10 76
Set WorkSheet  not Working 9 62
VB script to continue despite error 2 78
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

752 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