Search code examples
vbams-accessms-access-2016

Access VBA parameterized query: syntax error in the query clause is incomplete


 recup = "SELECT id_categorie FROM T_Categorie WHERE T_Categorie.libelle = " & TxtCategId.Value

''retrieve the number of the category which corresponds to the depot

    Set dbcaisse = CurrentDb
    Set rsT = dbcaisse.OpenRecordset(recup, dbOpenDynaset)
    categorie = rsT!id_categorie
      
    ''registration of the deposit
 
 Set dbcaisse = CurrentDb
 Set rsT = dbcaisse.OpenRecordset("T_Mouvement", dbOpenDynaset)

when the execution arrives at the level of Set rsT = dbcaisse.OpenRecordset(recup) I have this error

thank you for your answers


Solution

  • Not knowing your secret value, if present it could be text, thus must be quoted:

     recup = "SELECT id_categorie FROM T_Categorie WHERE T_Categorie.libelle = '" & TxtCategId.Value & "'"