473,406 Members | 2,352 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,406 software developers and data experts.

Passing a date parameter to an Access query in ASP

17
I have the followig code:


Expand|Select|Wrap|Line Numbers
  1. set conn=Server.CreateObject("ADODB.Connection")
  2. conn.Provider=provider
  3. conn.Open dbpath
  4. set rs = Server.CreateObject("ADODB.recordset")
  5.  
  6. ...
  7.  
  8.  
  9. sql="SELECT department, job, start, [end] FROM Qry_AssignedWeek WHERE employee='" & employee & "' ORDER BY start"
  10. rs.open sql, conn, sunday
Where the Qry_AssignedWeek is the following query in Access2003:

Expand|Select|Wrap|Line Numbers
  1. PARAMETERS sunday DateTime;
  2. SELECT *
  3. FROM Qry_AssignedNotCancelled
  4. WHERE (((Qry_AssignedNotCancelled.start) Between [sunday] And [sunday]+7)) OR (((Qry_AssignedNotCancelled.end) Between [sunday] And [sunday]+7));

this code generates the ASP error:

Provider (0x80020005)
Type mismatch.
/schedule/ViewMyShifts.asp, line 70


The "sunday" variable is a string representing a date in format "dd/mm/yyyy"

I have tried to change the "sunday" in "rs.open sql, conn, sunday" with many different options:
int(sunday)
CDate(sunday)
#23/09/2007#

etc.

All returning various errors.

Please, can anyone guide me around this problem?
Sep 20 '07 #1
2 6078
markrawlingson
346 Expert 100+
You could try something like this... and scrap the msAccess query all together.

This would calculate when sunday is, and return all records which fall within the last sunday to the next sunday. In the case of this week, as an example, it would return all records from Sunday the 15th of september to Sunday the 22nd of september.

Expand|Select|Wrap|Line Numbers
  1. If WeekDay(Date()) = 1 Then 'it's sunday
  2.    dDateStart = Date() ' it's sunday today so we want to start from today's date
  3. Else
  4.    'Today is not sunday, so we need to find when sunday is. To do this, we'll find the integer value of the weekday, and count backwards to sunday.
  5.    'If today is friday weekDay will return 6 - sunday would be 5 days ago. So weekday*-1 = -6 + 1 = -5
  6.    iDateChange = (WeekDay(Date())*-1)+1
  7.    dDateStart = DateAdd(d,iDateChange,Date())
  8. End If
  9. 'Now we have our start date, we just need our end date, which is easy
  10.  
  11. dDateEnd = DateAdd(d,7,dDateStart)
  12.  
  13. sSQL="SELECT department, job, start, datefield FROM yourtable WHERE employee='" & employee & "' AND datefield BETWEEN " & dDateStart& " AND " & dDateEnd & " ORDER BY datefield"
  14. rs.open sql, conn, 3, 3
  15.  
  16.  
I also don't know why you have rs.open sql, conn, sunday

You can't pass a variable through your recordset opening statement. This statement accepts: your sql query, the connection string to your db, and your vb constants. (adReadOnly, adLockOptomistic, etc)

Hope this helps,

Sincerely
Mark

I have the followig code:


Expand|Select|Wrap|Line Numbers
  1. set conn=Server.CreateObject("ADODB.Connection")
  2. conn.Provider=provider
  3. conn.Open dbpath
  4. set rs = Server.CreateObject("ADODB.recordset")
  5.  
  6. ...
  7.  
  8.  
  9. sql="SELECT department, job, start, [end] FROM Qry_AssignedWeek WHERE employee='" & employee & "' ORDER BY start"
  10. rs.open sql, conn, sunday
Where the Qry_AssignedWeek is the following query in Access2003:

Expand|Select|Wrap|Line Numbers
  1. PARAMETERS sunday DateTime;
  2. SELECT *
  3. FROM Qry_AssignedNotCancelled
  4. WHERE (((Qry_AssignedNotCancelled.start) Between [sunday] And [sunday]+7)) OR (((Qry_AssignedNotCancelled.end) Between [sunday] And [sunday]+7));

this code generates the ASP error:

Provider (0x80020005)
Type mismatch.
/schedule/ViewMyShifts.asp, line 70


The "sunday" variable is a string representing a date in format "dd/mm/yyyy"

I have tried to change the "sunday" in "rs.open sql, conn, sunday" with many different options:
int(sunday)
CDate(sunday)
#23/09/2007#

etc.

All returning various errors.

Please, can anyone guide me around this problem?
Sep 20 '07 #2
scf1984
17
Thanks! it's working:

Expand|Select|Wrap|Line Numbers
  1. sunday = CDate(sunday)
  2. sql="SELECT department, job, start, [end] FROM Qry_AssignedNotCancelled WHERE employee='"
  3. sql=sql & employee & "' " & "AND start BETWEEN #" & sunday & "# AND #" & sunday + 7 & "#"
  4.  
  5. rs.open sql, conn
(the varaiable "sunday" is given as a string "dd/mm/yyyy")

But I am still quite puzzled...
Is there a way to run an Access parameterized query from ASP?




You could try something like this... and scrap the msAccess query all together.

This would calculate when sunday is, and return all records which fall within the last sunday to the next sunday. In the case of this week, as an example, it would return all records from Sunday the 15th of september to Sunday the 22nd of september.

Expand|Select|Wrap|Line Numbers
  1. If WeekDay(Date()) = 1 Then 'it's sunday
  2.    dDateStart = Date() ' it's sunday today so we want to start from today's date
  3. Else
  4.    'Today is not sunday, so we need to find when sunday is. To do this, we'll find the integer value of the weekday, and count backwards to sunday.
  5.    'If today is friday weekDay will return 6 - sunday would be 5 days ago. So weekday*-1 = -6 + 1 = -5
  6.    iDateChange = (WeekDay(Date())*-1)+1
  7.    dDateStart = DateAdd(d,iDateChange,Date())
  8. End If
  9. 'Now we have our start date, we just need our end date, which is easy
  10.  
  11. dDateEnd = DateAdd(d,7,dDateStart)
  12.  
  13. sSQL="SELECT department, job, start, datefield FROM yourtable WHERE employee='" & employee & "' AND datefield BETWEEN " & dDateStart& " AND " & dDateEnd & " ORDER BY datefield"
  14. rs.open sql, conn, 3, 3
  15.  
  16.  
I also don't know why you have rs.open sql, conn, sunday

You can't pass a variable through your recordset opening statement. This statement accepts: your sql query, the connection string to your db, and your vb constants. (adReadOnly, adLockOptomistic, etc)

Hope this helps,

Sincerely
Mark
Sep 20 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: zlatko | last post by:
There is a form in an Access Project (.adp, Access front end with SQL Server) for entering data into a table for temporary storing. Then, by clicking a botton, several action stored procedures...
1
by: Michael DeLawter | last post by:
Using Access 2002. I have a chart in a report that is currently based on a query in which the user enters the start and end date for the chart to display. Both the start and end dates have been...
10
by: Kenneth | last post by:
I have a Query that consist of a lot of different sales data, and one of the colums are different date. The date goes from 1jan2003 til 31jan2003. in this Query I only want the salesdata for...
7
by: Nicolae Fieraru | last post by:
Hi All, I have a table tblProducts where I have four fields:\ Index, ProductName, EnterDate (as Date/Time - Medium Date), PurchaseDate (Date/Time - Medium Date) The EnterDate is automatically...
4
by: Tony | last post by:
Hey guys, I use Google Groups quite a bit as it is an enormous wealth of information, and now I need some help. I have created a query using parameters to capture a range of date, the date is...
2
by: Tony | last post by:
Hello everyone, Okay so here is my pickle! I have a field called ARCH_DATE within a table which has a date stored like "9/1/2004 23:50:00". What I would like to do is create a date range which...
0
by: Zlatko Matić | last post by:
Hi everybody! Recently I was struggling with client/server issues in MS Access/PostgreSQL combination. Although Access is intuitive and easy to use desktop database solution, many problems...
2
by: Julie Wardlow | last post by:
Help! I am calculating a future date using the DateAdd function in a query (the calculation also involves an IIf statement), and have managed to get this formula to produce the required result....
1
by: ShadesOfGrey | last post by:
Hello again. Thanks to Gord, I have this cool query that puts my student attendance records in a calendar format in Access 2003. PARAMETERS Text ( 255 ), IEEEDouble; TRANSFORM...
3
by: Fred's | last post by:
Hi Folks, I have a report which the record source is a query name: Query3 and in my Query3 I have this parameter "between And ". Therefore, when I open my report, it will ask for a Start Date...
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?
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.