a variable as where condition?

Fuga

Registered User.
Local time
Today, 04:30
Joined
Feb 28, 2002
Messages
566
Is it possible to use a variable in the where clause?


***

Dim rattdag as string, rattlopp as string

Set rsdogs = CurrentDb.OpenRecordset("SELECT Starter.Loppdatum, Starter.Startnummer where starter.loppdatum =" & rattdag & " and starter.startnummer =" & rattlopp " FROM Starter ORDER BY Starter.odds DESC;")

***

I keep getting an error message and I can´t figure it out.

Fuga.
 
3075 Syntax error in query expression? Please post errormessages to avoid guessing contests...

What are the datatypes of the fields? You'll need to use delimiters on the criteria based on the datatypes of the fields. Text fields need single quotes, dates need hash (#), numerics none.

You have declared both variables as strings (but you have not shown us what values are assigned to them, so it is a bit hard to guess...). By the names of the fields, I suspect "Loppdatum" is a date, and the entrant number, is it text or numeric? Here assuming text:

Set rsdogs = CurrentDb.OpenRecordset("SELECT Starter.Loppdatum, Starter.Startnummer where starter.loppdatum =#" & rattdag & "# and starter.startnummer = '" & rattlopp & "' FROM Starter ORDER BY Starter.odds DESC;")

There was also an ampersand (&) missing.

Note - depending on the date format in your regional settings, should loppdatum be a date, you might need to format the date too.
 
Thanks for the reply!

3075 - syntax error(missing operator) in query expression is indeed the message I get.

I might have made a misstake with the datatypes. "loppdatum" is indeed a date.

I´m not at work right now so I´ll have to check it out later.

I'll let you know how it works out.

Thanks.

Fuga.
 

Users who are viewing this thread

Back
Top Bottom