Avatar of Graeme McGilvray
Graeme McGilvray
Flag for Australia asked on

Search breakdown

Hi all and thanks in advance.


I would like to use a Recordset where I define the year, month, date


I have this code, however does not work, not really sure where to go from here:

Set Prod=oConnUSR.Execute("SELECT * FROM departures WHERE dep_date=>#"&Year(Date())&"# AND dep_date=>#"&Month(Date())&"# AND dep_date>#"&Day(Date())&"#")

Open in new window

I am just using Date() at the moment for testing, as they will be variables later on

VB Script* ASP ClassicASP

Avatar of undefined
Last Comment
Graeme McGilvray

8/22/2022 - Mon
aikimark

If dep_date field is a datetime field, then you shouldn't have to break up the search criteria with the date component comparisons.

What exactly is not working?
Graeme McGilvray

ASKER
Hi Aikimark, when I use just the datetime field, when the start of the month comes around, for some reason the month and date swap around and some products do not show (because of the date).
aikimark

Since you are in a non-American country, you are probably experiencing the mm/dd/yyyy vs. dd/mm/yyyy date formatting difference.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Graeme McGilvray

ASKER
Yes, that is correct
aikimark

what are the regional settings?
Graeme McGilvray

ASKER
How do you mean? Sorry a little unfamiliar with regional settings
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
aikimark

Regional settings is a Windows setting that determines how the operating system treats and displays data; things like your time zone and country.  When you enter dates, the system would expect your date to be in a particular format, based on these settings.
Graeme McGilvray

ASKER
Unfortunately I do not have control over where the website is hosted in the US, but im guessing in US format. On my home server, its in AU format, but same issue.
aikimark

Where/how does a "website" fit into your configuration?

How many servers are you using?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Graeme McGilvray

ASKER
I have the hosted server in the US (which is live and has the website), and a test server at my house/AU
aikimark

Is the back-end database MS Access, SQL Server, or some other RDBMS?
Graeme McGilvray

ASKER
MS Access
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
aikimark

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Graeme McGilvray

ASKER
So for 'yourdatevariable' use Date() ? ie today
aikimark

sure
Graeme McGilvray

ASKER
Thanks, I have just tried and got this error:

Microsoft VBScript runtime error '800a000d'
Type mismatch: '[string: " & Day(Date()) & "]'

Set Prod=oConnUSR.Execute("SELECT * FROM departures WHERE dep_date=> " & DateSerial( " & Year(Date()) & " , " & Month(Date()) & " , " & Day(Date()) & " ) )


Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
aikimark

I think there's a missing quote character near the end.  Try this:
& Day(Date()) & " )" )

Open in new window

Graeme McGilvray

ASKER
I took it out because there was 1 too many, error below:

Microsoft VBScript compilation error '800a0409'
Unterminated string constant
/home.asp, line 576
Set Prod=oConnUSR.Execute("SELECT * FROM departures WHERE dep_date=> " & DateSerial( " & Year(Date()) & " , " & Month(Date()) & " , " & Day(Date()) & " ) " )
-------------------------------------------------------------------------------------------------------------------------------------------------------------^

Open in new window

aikimark

Ah.  My code was missing a quote from the beginning of the second line.  Please test this:
Set Prod=oConnUSR.Execute("SELECT * FROM departures WHERE dep_date=> " &  _ 
    "DateSerial(" & Year(yourdatevariable) & ", " & Month(yourdatevariable) & ", " & _
    Day(yourdatevariable) & ")" )

Open in new window

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Graeme McGilvray

ASKER
Ah thanks for that, I have added it in and now have this error:

Microsoft JET Database Engine error '80040e14'
Syntax error (missing operator) in query expression 'dep_date=> DateSerial(2022, 3, 2)'.
/home.asp, line 576

Open in new window

aikimark

Please check the name of the datetime field in your departures table.

Also, try enclosing the name of the field in square brackets:
[dep_date]=>

Open in new window

Graeme McGilvray

ASKER
Double checked the field name, definitely dep_date. Do you need to know the Format and such?

Same error with brackets
Microsoft JET Database Engine error '80040e14'
Syntax error (missing operator) in query expression '[dep_date]=> DateSerial(2022, 3, 3)'.
/home.asp, line 576

Open in new window

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
aikimark

Please post the statement you are using.
aikimark

Got it. The comparison operator needs to be reversed.
[dep_date] >=

Open in new window

Graeme McGilvray

ASKER
Just updated it, this is the error:
ADODB.Recordset error '800a0cc1'
Item cannot be found in the collection corresponding to the requested name or ordinal.
/home.asp, line 579

Open in new window

This is the code:
   Set Prod=oConnUSR.Execute("SELECT * FROM departures WHERE [dep_date]>= " &  _ 
    "DateSerial(" & Year(Date()) & ", " & Month(Date()) & ", " & _
    Day(Date()) & ")" )

Open in new window

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
aikimark

double check the table name and the field name
Graeme McGilvray

ASKER
Just checked again, letter for letter, its all correct
aikimark

If someone has made a change to a table, you might need to refresh the tables collection
Your help has saved me hundreds of hours of internet surfing.
fblack61
Graeme McGilvray

ASKER
No changes have been made to the table

My current statement works with it:
Set Prod=oConnUSR.Execute("SELECT * FROM departures WHERE dep_date>#"&Date()&"# ORDER BY dep_date")


Open in new window

aikimark

If you open the database on your PC and run the (DateSerial) resolved string expression query, what do you see?
Graeme McGilvray

ASKER
Data type mismatch in criteria expression
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
aikimark

what is the data type of the dep_date column?
Graeme McGilvray

ASKER
date/time
aikimark

If you set a breakpoint at the execute statement, copy/paste the query string into the Immediate window (Ctrl+G) and put a question mark character at the very start of the line, before the quote character.

Example:
?"SELECT * FROM departures WHERE [dep_date]>= " &  _ 
    "DateSerial(" & Year(Date()) & ", " & Month(Date()) & ", " & _
    Day(Date()) & ")"

Open in new window

Then copy/paste the result of that operation (? is actually debug.print) into a query design window (SQL view) and run the query.  Do you get the same error?  If no error, or a different error message, what do you see?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Graeme McGilvray

ASKER
Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT' or ' UPDATE'.
aikimark

What did you paste (what was the SQL you were trying to run)?
Graeme McGilvray

ASKER
The same SQL statement as you gave me:

?"SELECT * FROM departures WHERE [dep_date]>= " &  _ 
    "DateSerial(" & Year(Date()) & ", " & Month(Date()) & ", " & _
    Day(Date()) & "

Open in new window

Seems like it didnt like the ?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
aikimark

Did you press the Enter key?
If so, it would resolve that string expression.  The resolved string expression is what you should copy/paste into the query design SQL window.
Graeme McGilvray

ASKER
I cut and pasted what you gave me into the SQL View and then Ran it.
aikimark

I need you to press the Enter key in the Immediate window after you paste the string and prefix it with a question mark.  Since this may be multiple lines, you may need to press the Enter key multiple times, until you see a new line appear in the Immediate window.  That new line is what you copy/paste into the query SQL view.

Sorry for the confusion.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Graeme McGilvray

ASKER
I pasted it into the SQL view, pressed enter 4 times after the paste, ran the query, same error

I am not really sure I understand what I am doing correct to your instruction
aikimark

Does your query contain question mark characters?  It shouldn't.
Graeme McGilvray

ASKER
it does at the front, like you gave me to use
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Graeme McGilvray

ASKER

Graeme McGilvray

ASKER
I was playing around with how DateSerial should be showing, figured out it should be like this

dep_date>"&("DateSerial("&Year(Date)&","&Month(Date)&","&Day(Date)&")")&"

Open in new window

For some reason needed brackets around it and now it works fine
aikimark

First, you copy/paste the quoted string into the Immediate window, prefix the first quote with a question mark and press the Enter key until you see a new line appear below what you pasted.

Second, you copy/paste that new line (should not start with a quote character) from the Immediate window into your SQL view window.

Third, you run the query.

Four, report the results (good, error messages, etc.)
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
Graeme McGilvray

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
aikimark

What did you do to "fix" the problem?
Graeme McGilvray

ASKER
I posted how I fixed it 3 posts back