473,385 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Using form's date field value in sql query

I'm trying to do something that I thought was simple but has already taken
me hours. I'm trying to use a value from an unbound date field in a query.
Amongst others I tried the following, but I can't get it to work. I tried
several different quotings etc but no luck.

strSQL = "SELECT Transactie.* INTO CatTemp"
strSQL = strSQL & " FROM Transactie"
strSQL = strSQL & " WHERE (([Transactie.Rentedatum]) >=
me.MyFormsDateField);"
DBEngine(0)(0).Execute strSQL, dbFailOnError

Anyone an idea?

Another question. Is there some kind of tool that let's you easily convert
the sql-code from the querybuilder to the visual basic editor? Or is it
normal practice having to divide the query text in separate strings
manually?

Thanks,
john
Jan 27 '07 #1
6 7196
"john" <jo**@test.comwrote in message
<5Z******************************@casema.nl>:
I'm trying to do something that I thought was simple but has already
taken me hours. I'm trying to use a value from an unbound date field
in a query. Amongst others I tried the following, but I can't get it
to work. I tried several different quotings etc but no luck.

strSQL = "SELECT Transactie.* INTO CatTemp"
strSQL = strSQL & " FROM Transactie"
strSQL = strSQL & " WHERE (([Transactie.Rentedatum]) >=
me.MyFormsDateField);"
DBEngine(0)(0).Execute strSQL, dbFailOnError

Anyone an idea?

Another question. Is there some kind of tool that let's you easily
convert the sql-code from the querybuilder to the visual basic
editor? Or is it normal practice having to divide the query text in
separate strings manually?

Thanks,
john
I think you'll first need to concatenate the value of the form control
into the sql string, in stead of the reference, then Jet needs an
unambiguous date format, wher I prefer the ISO 8601

.... " WHERE Rentedatum >= # & _
format$(me.MyFormsDateField, "yyyy-mm-dd") & "#"

For other acceptable formats, and more information, check out
Allen Brownes article http://allenbrowne.com/ser-36.html

--
Roy-Vidar
Jan 27 '07 #2
"RoyVidar" <ro*************@yahoo.nowrote in message
<mn***********************@yahoo.no>:
"john" <jo**@test.comwrote in message
<5Z******************************@casema.nl>:
>I'm trying to do something that I thought was simple but has already
taken me hours. I'm trying to use a value from an unbound date
field in a query. Amongst others I tried the following, but I can't
get it to work. I tried several different quotings etc but no luck.

strSQL = "SELECT Transactie.* INTO CatTemp"
strSQL = strSQL & " FROM Transactie"
strSQL = strSQL & " WHERE (([Transactie.Rentedatum]) >=
me.MyFormsDateField);"
DBEngine(0)(0).Execute strSQL, dbFailOnError

Anyone an idea?

Another question. Is there some kind of tool that let's you easily
convert the sql-code from the querybuilder to the visual basic
editor? Or is it normal practice having to divide the query text in
separate strings manually?

Thanks,
john

I think you'll first need to concatenate the value of the form
control into the sql string, in stead of the reference, then Jet
needs an unambiguous date format, wher I prefer the ISO 8601

... " WHERE Rentedatum >= # & _
format$(me.MyFormsDateField, "yyyy-mm-dd") & "#"

For other acceptable formats, and more information, check out
Allen Brownes article http://allenbrowne.com/ser-36.html
Forgot (at least one) quote, sorry

.... " WHERE Rentedatum >= #" & _
format$(me.MyFormsDateField, "yyyy-mm-dd") & "#"

--
Roy-Vidar
Jan 27 '07 #3
Hy John,
a few months ago I faced the same problem and this was the solution:
You have to convert your date into SQL-ready date format:

Example:
MyDate = Me.MyDateField
SQLMyDate = "#" & Month(MyDate) & "/" & Day(MyDate) & "/" &
Year(MyDate) & "#"
MsgBox MyDate & vbCrLf & SQLMyDate

after converting SQLMyDate should look like: #26/1/2006#

this variable You can use in SQL statements:

strSQL = "SELECT * FROM MyTable WHERE MyTable.MyDateField = " +
SQLMyDate
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)
....
It worked fine for me, hope it does for you

Your last question: I also don't know a tool to get SQL code from the
querybuilder. I'm used to seperate the SQL code into different parts
because it's more flexible and clear when You use it within functions
where You have to deal with variables
strSELECT = "... " ' don't forget the blank at the end of the
strings
strFROM = "... "
strWHERE = "... "
strORDER = "..."

and at the end You add the SQL code together into one string
strSQL = strSELECT + strFROM + strWHERE + strORDER

On 27 Jan., 10:59, "john" <j...@test.comwrote:
I'm trying to do something that I thought was simple but has already taken
me hours. I'm trying to use a value from an unbound date field in a query.
Amongst others I tried the following, but I can't get it to work. I tried
several different quotings etc but no luck.

strSQL = "SELECT Transactie.* INTO CatTemp"
strSQL = strSQL & " FROM Transactie"
strSQL = strSQL & " WHERE (([Transactie.Rentedatum]) >=
me.MyFormsDateField);"
DBEngine(0)(0).Execute strSQL, dbFailOnError

Anyone an idea?

Another question. Is there some kind of tool that let's you easily convert
the sql-code from the querybuilder to the visual basic editor? Or is it
normal practice having to divide the query text in separate strings
manually?

Thanks,
john
Jan 27 '07 #4
It took me some time but now it works. I used your example and the format
Allen describes, the native SQL notation mm-dd-yyyy. I wonder what has ever
been the logic of this notation???

Thanks a lot Vidar.
john

"RoyVidar" <ro*************@yahoo.noschreef in bericht
news:mn***********************@yahoo.no...
"RoyVidar" <ro*************@yahoo.nowrote in message
<mn***********************@yahoo.no>:
>"john" <jo**@test.comwrote in message
<5Z******************************@casema.nl>:
>>I'm trying to do something that I thought was simple but has already
taken me hours. I'm trying to use a value from an unbound date
field in a query. Amongst others I tried the following, but I can't
get it to work. I tried several different quotings etc but no luck.

strSQL = "SELECT Transactie.* INTO CatTemp"
strSQL = strSQL & " FROM Transactie"
strSQL = strSQL & " WHERE (([Transactie.Rentedatum]) >=
me.MyFormsDateField);"
DBEngine(0)(0).Execute strSQL, dbFailOnError

Anyone an idea?

Another question. Is there some kind of tool that let's you easily
convert the sql-code from the querybuilder to the visual basic
editor? Or is it normal practice having to divide the query text in
separate strings manually?

Thanks,
john

I think you'll first need to concatenate the value of the form
control into the sql string, in stead of the reference, then Jet
needs an unambiguous date format, wher I prefer the ISO 8601

... " WHERE Rentedatum >= # & _
format$(me.MyFormsDateField, "yyyy-mm-dd") & "#"

For other acceptable formats, and more information, check out
Allen Brownes article http://allenbrowne.com/ser-36.html

Forgot (at least one) quote, sorry

... " WHERE Rentedatum >= #" & _
format$(me.MyFormsDateField, "yyyy-mm-dd") & "#"

--
Roy-Vidar


Jan 27 '07 #5
RoyVidar <ro*************@yahoo.nowrote in news:mn.da9b7d71986e0974.59509
@yahoo.no:
I think you'll first need to concatenate the value of the form control
into the sql string, in stead of the reference, then Jet needs an
unambiguous date format, wher I prefer the ISO 8601

... " WHERE Rentedatum >= # & _
format$(me.MyFormsDateField, "yyyy-mm-dd") & "#"
A simple hack is

.... " WHERE Rentedatum >=" & CDbl(MyFormsDateField.Value)
Jan 27 '07 #6
"Lyle Fairfield" <no@thanks.comwrote in message
<Xn******************@216.221.81.119>:
RoyVidar <ro*************@yahoo.nowrote in
news:mn.da9b7d71986e0974.59509 @yahoo.no:
>I think you'll first need to concatenate the value of the form
control into the sql string, in stead of the reference, then Jet
needs an unambiguous date format, wher I prefer the ISO 8601

... " WHERE Rentedatum >= # & _
format$(me.MyFormsDateField, "yyyy-mm-dd") & "#"

A simple hack is

... " WHERE Rentedatum >=" & CDbl(MyFormsDateField.Value)
Ah, yes - that's OK for *dates*, but when there's a time fraction ....

....say where I live, then I'd get 3075 Syntax error (comma) in query
expression...

.... because we use comma as decimalseparator, which makes Jet barf on
39109,6325462963

Replace(CDbl(MyFormsDateField.Value), ",", ".") would work, as will
converting to integer ;-)

--
Roy-Vidar
Jan 27 '07 #7

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

Similar topics

3
by: Steve | last post by:
Form FrmRestock's recordsource is QryFrmRestock. The TransactionDate field's criteria is set ats: Forms!FrmRestock!LastXDays. LastXDays on the form is a combobox where the selections are 30, 60...
5
by: Jonny | last post by:
Hello, I have a List Box in my DB on a form, which when the form is opened, the list box displays the date relating to the records. (Date, Person etc) How can I get it so that when I open the...
6
by: Megan | last post by:
Hi everybody- I'm trying to use a checkbox to control whether or not a date field in a query "Is Null" or "Is Not Null." I have 2 date fields: InDate and OutDate. If there is an OutDate, then...
2
by: Sherman H. | last post by:
I have a few questions for crosstab and popup form questions: 1. I created a crosstab as follows: IT Financial Operation John 21 22 ...
10
by: sandraz444 | last post by:
I have an expression in the query under my form to autofill the date under a certain condition but it wont write to the underlying table?? The date shows in the form but not the table. Does anyone...
2
by: jcf378 | last post by:
hi all. I have a form which contains a calculated control ("days") that outputs the # of days between two dates (DateDiff command between the fields and ). However, when I click "Filter by...
23
by: Steven TK | last post by:
Hi everyone, I wonder who can help me on the filter the Start Date and End Date. I still cannot manage to filter it. Eg. When the user click the StartDate(comboBox as 16/7/07), the Start...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
2
by: sbettadpur | last post by:
Hi everybody, Hi iam strugling with more than one submit buttons with in one form here is my code <form method="post" action="Offer.php" name='issueFrm' onSubmit="return fullOfferfields();">...
0
MMcCarthy
by: MMcCarthy | last post by:
Rather than using the Access design view change the view to SQL. I am going to attempt to outline the general syntax used for SQL queries in Access. Angle brackets <> are used in place of some...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.