1

I have been trying to fix this code, but have no idea why I keep having too few parameters :1 error

strSQL = "UPDATE tblProduct "
strSQL = strSQL & "SET [Verified_By] = " & Me.txtCurrentUser & "" & " , [Verified_Date] = #" & Me.txtAuto_Date & "#" & ", [Status] = ""Verified"""
strSQL = strSQL & " WHERE [Status] = ""Not Verified""" & " AND [Verify] = -1"

I am still having troubles with the syntax for attaching variables to queries in VBA. The query works in my UPDATE statement in Access.

This is what I use in Access query:

UPDATE tblProduct SET Verified_By = forms!frmVerificationProduct!txtcurrentuser, Verified_date = forms!frmVerificationProduct!txtAuto_date, Status = "Verified"
WHERE verify = -1 AND Status = "Not Verified";
0

2 Answers 2

1

If the tblProduct.Verified_By field is text datatype, the problem is that the UPDATE is supplying an unquoted text value. And when Access sees the unquoted text value, it assumes that must be a parameter for which you have not supplied a value.

In that case, you could revise the code to include the needed quotes or switch to a parameter query and not be bothered with quotes ...

Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
strSQL = "UPDATE tblProduct" & vbCrLf & _
    "SET [Verified_By] = [pCurrentUser], [Verified_Date] = [pAuto_Date], [Status] = 'Verified'" & vbCrLf & _
    "WHERE [Status] = 'Not Verified' AND [Verify] = -1"
Debug.Print strSQL ' <- view in Immediate window; Ctrl+g will take you there
Set db = CurrentDb
Set qdf = db.CreateQueryDef(vbNullString, strSQL)
qdf.Parameters("pCurrentUser").Value = Me!txtCurrentUser.Value
qdf.Parameters("pAuto_Date").Value = Me!txtAuto_Date.Value
qdf.Execute dbFailOnError
Sign up to request clarification or add additional context in comments.

Comments

1

This should do:

strSQL = "UPDATE tblProduct "
strSQL = strSQL & "SET [Verified_By] = " & Me.txtCurrentUser & ", [Verified_Date] = #" & Format(Me.txtAuto_Date, "yyyy\/mm\/dd") & "#, [Status] = 'Verified' "
strSQL = strSQL & "WHERE [Status] = 'Not Verified' AND [Verify] = -1"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.