473,395 Members | 1,343 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,395 software developers and data experts.

Date and parameter issues with dynamic SQL creation

Hi everyone,

I have this piece of VBA script:

' checking the DOB field to see if we constrain on the date
If Len(Me.EmpDOBTxt & "") > 0 Then
strWhere = strWhere & " AND [Employee].[DOB] <= #" & Me.DOBTxt &
"#"
End If

' check the Banking details fields
If Me.EmpVISAchk = True Then
strWhere = strWhere & " AND [Employee Banking].[VISA]=true"
End If

Basically, I am pulling back input from a form and using it to create
a whereCondition to feed into a report.

Problems:
1. The first piece of code checking DOB works, but only if the date
has a day that is 2 digits, ie. 30/06/2004. If you provide a date like
01/07/2004, it creates the SQL statement truncating the leading '0',
thus 1/07/2004. This then retuns no results when it should return the
same result as the other date entered, ie. 30/06/2004. Don't know why.
Both [Employee].[DOB] and Me.EmpDOBTxt are of Short date type.

2. If the user checks me.EmpVISAchk, when the code runs, a dialog box
is presented asking to provide parameter "[Employee Banking]". Again,
I have no idea why this is happening....... I have tried encasing the
statement like:

(([Employee Banking].[VISA])=true)

and tried many different variations of 'true' - ie. -1, True, (1),
(-1).... I am also pretty sure that have no bound fields on my form,
but am not totally sure - how do you check this?

Any help very much appreciated.

Thanks,

A
Nov 13 '05 #1
5 1870


--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"DataB" <ab******@hotmail.com> wrote in message
news:6c**************************@posting.google.c om...
Hi everyone,

I have this piece of VBA script:

' checking the DOB field to see if we constrain on the date
If Len(Me.EmpDOBTxt & "") > 0 Then
strWhere = strWhere & " AND [Employee].[DOB] <= #" & Me.DOBTxt &
"#"
End If

' check the Banking details fields
If Me.EmpVISAchk = True Then
strWhere = strWhere & " AND [Employee Banking].[VISA]=true"
End If

Basically, I am pulling back input from a form and using it to create
a whereCondition to feed into a report.

Problems:
1. The first piece of code checking DOB works, but only if the date
has a day that is 2 digits, ie. 30/06/2004. If you provide a date like
01/07/2004, it creates the SQL statement truncating the leading '0',
thus 1/07/2004. This then retuns no results when it should return the
same result as the other date entered, ie. 30/06/2004. Don't know why.
Both [Employee].[DOB] and Me.EmpDOBTxt are of Short date type.

2. If the user checks me.EmpVISAchk, when the code runs, a dialog box
is presented asking to provide parameter "[Employee Banking]". Again,
I have no idea why this is happening....... I have tried encasing the
statement like:

(([Employee Banking].[VISA])=true)

and tried many different variations of 'true' - ie. -1, True, (1),
(-1).... I am also pretty sure that have no bound fields on my form,
but am not totally sure - how do you check this?

Any help very much appreciated.

Thanks,

A

Nov 13 '05 #2
Issue 1 - Dates
A literal date in the SQL string must be formatted American. Use:

strWhere = strWhere & " AND [Employee].[DOB] <= #" & Format(Me.DOBTxt,
"mm/dd/yyyy") & "#"

For more information on ensuring that Access interprets our dd/mm/yyyy dates
correctly, see:
International Date Formats in Access
at:
http://members.iinet.net.au/~allenbrowne/ser-36.html
Issue 2 - Parameter
Anything Access does not recognise it assumes is a parameter. This suggests
that there is no table(?) named Employee Banking in the recordset you are
referring to. Perhaps it has different spelling, different spacing, or
perhaps it is not in that query at all.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"DataB" <ab******@hotmail.com> wrote in message
news:6c**************************@posting.google.c om...
Hi everyone,

I have this piece of VBA script:

' checking the DOB field to see if we constrain on the date
If Len(Me.EmpDOBTxt & "") > 0 Then
strWhere = strWhere & " AND [Employee].[DOB] <= #" & Me.DOBTxt &
"#"
End If

' check the Banking details fields
If Me.EmpVISAchk = True Then
strWhere = strWhere & " AND [Employee Banking].[VISA]=true"
End If

Basically, I am pulling back input from a form and using it to create
a whereCondition to feed into a report.

Problems:
1. The first piece of code checking DOB works, but only if the date
has a day that is 2 digits, ie. 30/06/2004. If you provide a date like
01/07/2004, it creates the SQL statement truncating the leading '0',
thus 1/07/2004. This then retuns no results when it should return the
same result as the other date entered, ie. 30/06/2004. Don't know why.
Both [Employee].[DOB] and Me.EmpDOBTxt are of Short date type.

2. If the user checks me.EmpVISAchk, when the code runs, a dialog box
is presented asking to provide parameter "[Employee Banking]". Again,
I have no idea why this is happening....... I have tried encasing the
statement like:

(([Employee Banking].[VISA])=true)

and tried many different variations of 'true' - ie. -1, True, (1),
(-1).... I am also pretty sure that have no bound fields on my form,
but am not totally sure - how do you check this?

Nov 13 '05 #3
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in
news:41***********************@per-qv1-newsreader-01.iinet.net.au:
A literal date in the SQL string must be formatted American. Use:

strWhere = strWhere & " AND [Employee].[DOB] <= #" & Format(Me.DOBTxt,
"mm/dd/yyyy") & "#"


If you know of some replicable situation in Access or JET SQL where
yyyy-mm-dd format
results in an error or problem, please, post it here.

--
Lyle
--
use iso date format: yyyy-mm-dd
http://www.w3.org/QA/Tips/iso-date
--
The e-mail address isn't, but you could use it to find one.
Nov 13 '05 #4
ab******@hotmail.com (DataB) wrote in message news:<6c**************************@posting.google. com>...
Hi everyone,

I have this piece of VBA script:


Could you post all of it, please, particularly the rest of the SQL
that the dynamic "where" clause pertains to?

Edward
--
The reading group's reading group:
http://www.bookgroup.org.uk
Nov 13 '05 #5
Hi Lyle

No: I believe that JET will interpret that correctly, but it is not the JET
standard.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Lyle Fairfield" <Lo******@FFDBA.Com> wrote in message
news:Xn******************@130.133.1.4...
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in
news:41***********************@per-qv1-newsreader-01.iinet.net.au:
A literal date in the SQL string must be formatted American. Use:

strWhere = strWhere & " AND [Employee].[DOB] <= #" & Format(Me.DOBTxt,
"mm/dd/yyyy") & "#"


If you know of some replicable situation in Access or JET SQL where
yyyy-mm-dd format
results in an error or problem, please, post it here.

--
Lyle
--
use iso date format: yyyy-mm-dd
http://www.w3.org/QA/Tips/iso-date
--
The e-mail address isn't, but you could use it to find one.

Nov 13 '05 #6

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

Similar topics

2
by: Jon | last post by:
Hi, I am trying to pick up records from a date range without much luck. For my example below I am trying to pick up all records made in the last month. However none are being found (my code is...
10
by: Jack | last post by:
Hi, I cannot get the date format correctly in dynamic sql statement, after trying various ways of handling it. I need some help with the date format in the following dynamic sql statement. Any...
3
by: acko bogicevic | last post by:
Hi everybody On page i have text box txtDate. User writes date in dd.mm.yyyy format. When the button btnSearch is clicked i have to query sqlserver 2000 database. Here is a code: Private Sub...
5
by: jeff | last post by:
i have written a program with date format as m/d/yyyy when i deploy it to client's machine, due to the client use d/m/yyyy format the Select SQL statement return some record wrongly. how can i...
1
by: A.Dagostino | last post by:
i have in my page an input text with a date like this "18/10/2005" i need to convert this value to lunch a select on SQL2000 like this "WHERE (dataAssunzione = CONVERT(DATETIME, '2005-10-18...
0
by: Pascal Costanza | last post by:
Dynamic Languages Day @ Vrije Universiteit Brussel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Monday, February 13, 2006, VUB Campus Etterbeek The VUB (Programming Technology Lab,...
2
by: wgblackmon | last post by:
Hi, I have a parameter that is being input as a String via Crystal Reports. It's called 'School Year' and a typical value is '2006'. I need to be able to create a 'Date' that is compared to a...
2
by: Billy | last post by:
This string is supposed to provide all records from an MDB database that match the courier and date specified in the query. I Response.Write the query and I get a date as 1/27/2007. The date...
7
by: =?Utf-8?B?U3R1?= | last post by:
I have a ASP.NET Ajax app (using client library) calling ASP.NET Ajax-enabled web services. We are making use of the javascript proxies generated by ASP.NET Ajax. The problem we have is that the...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.