0

I want to make update query with Parameters , the code I have doesn't work as I took the insert statement and made some changes to it

Dim db As DAO.Database
    Dim qdf As DAO.QueryDef
    Dim strUpdate As String
    strUpdate = "Update tblClients set [Client Name] = [Client Name],[Client Address] = [Client Address], [Client National ID] = [Client National ID], [phone1] = [phone1], [phone2] = [phone2], [phone3] = [phone3]"
    Set db = CurrentDb
    Set qdf = db.CreateQueryDef("", strUpdate)
    qdf.Parameters("Client Name").Value = txtName
    qdf.Parameters("Client Address").Value = txtAddress
    qdf.Parameters("Client National ID").Value = txtNationalID
    qdf.Parameters("phone1").Value = txtPhone1
    qdf.Parameters("phone2").Value = txtPhone2
    qdf.Parameters("phone3").Value = txtPhone3
    qdf.Execute dbFailOnError
    Set qdf = Nothing
    Set db = Nothing

and the error i get is : Error 3265 Item not found in this collection

Ali El-Boghdady
  • 145
  • 1
  • 11
  • 2
    You haven't declared the parameters in SQL. See this: https://stackoverflow.com/questions/50102431/pass-string-variable-without-quotes-in-query-vba/50102644#50102644 – Kostas K. Mar 26 '21 at 10:04
  • 1
    Your main error is that you use field names as parameters, though. If you'd use something like `pClientName` as the parameter name it'd work fine. – Erik A Mar 26 '21 at 17:00

0 Answers0