SQL-Statment Error "No value given for one or more required parame

G

Guest

I just could not figure out what is wrong or missing - here my sample code:

Dim horse_recordset As New ADODB.Recordset
Dim SQLstmt As String
Dim xyz As Integer

xyz = 13

SQLstmt = "SELECT [Horse-ID], [Horse Name], [Registration Nummer],
[Breed] FROM Horses WHERE (Horses.[Horse-ID] = xyz);"

horse_recordset.Open SQLstmt, CurrentProject.Connection,
adOpenForwardOnly, adLockReadOnly

Regardless of what I have tried I always get the same error - if I enter a
specific value in the query for ex. I "hard-code" 13 into the query instead
of xyz the query runs with no error - therefore it must have something to do
the way I use or declare the variable xyz or the syntax.

PLEASE HELP!!!!
 
A

Allen Browne

Concatenate the number into the string:

SQLstmt = "SELECT [Horse-ID], [Horse Name], [Registration Nummer],
[Breed] FROM Horses WHERE (Horses.[Horse-ID] = " & xyz & ");"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top