Link to home
Start Free TrialLog in
Avatar of Taylor814
Taylor814

asked on

INSERT INTO help (MS Access and VB6)

I cannot seem to get this statement to work. It throws a Syntax Error
MyConnAcct.Execute ("INSERT INTO UserAccounts ([attempts]) WHERE ID =" & Form1.curracct & " VALUES (" & Form1.LoginCounts & ")")

Open in new window

Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Try this:

MyConnAcct.Execute "INSERT INTO UserAccounts ([attempts]) WHERE ID =" & Form1.curracct & " VALUES (" & Form1.LoginCounts & ")"
use this.. an Insert statement do not have a where cluase..

MyConnAcct.Execute ("INSERT INTO UserAccounts ([attempts]) " VALUES (" & Form1.LoginCounts & ")")
it should be

MyConnAcct.Execute ("INSERT INTO UserAccounts ([attempts])  VALUES (" & Form1.LoginCounts & ")")
ASKER CERTIFIED SOLUTION
Avatar of Taylor814
Taylor814

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can not use the WHERE statement in the INSERT.

If you want to update the login attempts for a certain id, use the UPDATE statement, assuming
the ID exists in the table:


MyConnAcct.Execute("UPDATE UserAccounts SET [attempts]=" & Form1.LoginCounts & " WHERE ID=" & Form1.curracct)

Open in new window

an update and an insert statement structures differs. You asked an insert but resulted with an update statement.
"You can not use the WHERE statement in the INSERT."

Sure you can.  Example:

INSERT INTO Table1 ( FIELD1 )
SELECT Table2.FIELD1
FROM Table2
WHERE (((Table2.ID)=3));


mx
DatabaseMX the where clause is not a part of the insert statement its a part of the select statement which is supplying values to the insert statement.
What I posted is an Access Append query example ... but I see what you meant by that post.

mx