Update
The cause is position
is a ANSI 92 reserved word in Microsoft Access - see ACC2002: Error with ANSI-92 Reserved Words When SQL Server Compatibility Syntax (ANSI 92) Is Enabled
To workaround this simply encapsulate your field in square brackets []
(Updated my example below).
[position] = ?
Update
Looks like the error your reporting has nothing to do with your code.
Your using ADODB.Command
but setting variables in the CommandText
which bypasses the protection using ADODB.Command
gives you when executing Parametrised Queries.
Try this;
Dim sqlgetad1, rs
Set sqlgetad1 = Server.CreateObject("ADODB.Command")
With sqlgetad1
'Assuming justlistit_changes is your connection string variable.
.ActiveConnection = justlistit_changes
.CommandType = adCmdText
'******** Avoid any clashes with ANSI 92 reserved words ********
.CommandText = "Select * from ads where [county] = ? and [position] = ?"
.Prepared = true
.Parameters.Append(.CreateParameter("@county", adVarChar, adParamInput, 100))
'Assuming your position field is actually a numeric value.
.Parameters.Append(.CreateParameter("@position", adInteger, adParamInput, 4))
.Parameters("@county").Value = selcounty
.Parameters("@position").Value = 1
Set rs = .Execute()
End With
If your position
field is not an numeric replace with
.Parameters.Append(.CreateParameter("@position", adVarChar, adParamInput, 10))
.Parameters("@position").Value = "1"
If you have trouble with the ADO named constants like adCmdText
for example have a look at how to use METADATA to import DLL constants.