Below query is showing error
Please help :
DoCmd.RunSQL ("insert into tbltesting (IsDiff)values ('Yes') where empid= '" & Me.txtEmpId.Value & "' and testid= '" & Me.txtAutoNumber.Value & "'")
Below query is showing error
Please help :
DoCmd.RunSQL ("insert into tbltesting (IsDiff)values ('Yes') where empid= '" & Me.txtEmpId.Value & "' and testid= '" & Me.txtAutoNumber.Value & "'")
Does the empID record already exist in tblTesting? If so, you want an update:
UPDATE tblTesting
SET IsDiff = 'Yes'
WHERE empid = ...
and I won't get on my SQL injection soapbox...
Why do you have quotes around your empid/testid values? Are they strings or numbers? If numbers, watch out what you pass them to avoid conversion errors.
Well, one problem is that your query is vulnerable to sql injection. Never never NEVER concatenate values from user inputs directly into a query string. Instead, use an ADO.Command object along with real query parameters or parameterized SQL executed with DAO or similar.
Here is an example.
Insert is creating/adding a new row to the table - the record never existed. Update changes one or more fields in a record thats already saved in the table.
So an insert statement would not have a "where" clause - that would be an "update" statement you would use in this case.
You either need (if you are creating a brand-new record in your DB) -
DoCmd.RunSQL ("insert into tbltesting (IsDiff)values ('Yes') '")
Or you need (if you are changing some fields in an already-existing record ) -
DoCmd.RunSQL ("update tbltesting set IsDiff = 'Yes' where empid= '" & Me.txtEmpId.Value & "' and testid= '" & Me.txtAutoNumber.Value & "'")
I'm going to guess that empid and testid are numeric, and you're setting them off like they're strings in the SQL statement. Remove the single-quotes that you've wrapped around your field references.
DoCmd.RunSQL (" Update tbltesting set IsDiff ='Yes' where empid= " & Me.txtEmpId.Value & " and testid= " & Me.txtAutoNumber.Value & ";")