-1

I'm passing a variable to an SQL query.

Dim accept As String
accept = Cursor1.GetString("accepted_id")
    Msgbox(accept, "")  
    Cursor1 = SQL1.ExecQuery("SELECT answer FROM answers WHERE accepted_id =" & " 'accept' " )

There's more code but that should be enough. There are no errors and the msgbox shows the correct answer. it all looks good but it's not retrieving any results.

If I hardcode the answer instead of the variable it works, such as,

 Dim accept As String
    accept = Cursor1.GetString("accepted_id")
        Msgbox(accept, "")  
        Cursor1 = SQL1.ExecQuery("SELECT answer FROM answers WHERE accepted_id =" & " 'CD6028' " )

The msgbox shows CD6028.

The results show show in a listview but nothing.

GMB
  • 216,147
  • 25
  • 84
  • 135
user7668482
  • 151
  • 6
  • You needed to `msgbox` the sql query to see your error. Not the variable though a good first step. – catcat Jan 21 '19 at 06:48

1 Answers1

2

It seems like you are passing litteral string accept to the variable instead of variable accept itself.

Replace this :

Cursor1 = SQL1.ExecQuery("SELECT answer FROM answers WHERE accepted_id =" & " 'accept' " )

With :

Cursor1 = SQL1.ExecQuery("SELECT answer FROM answers WHERE accepted_id = '" & accept & "'")
GMB
  • 216,147
  • 25
  • 84
  • 135