Link to home
Start Free TrialLog in
Avatar of tonikaram
tonikaram

asked on

sql code to INSERT a row to a table in SQL server?

I have an access form with a few text fields, and a button.

Once this button is clicked, I would like to insert to a table on my sql server a row with thvalues picked up from the few text fields places above that button.

This code is not working:

CurrentDb.Execute "INSERT into dbo_tblLiveActions values (Ref,Action_ID,Person,ActionDate,0)"


It is saying "Too few parameters. Expected 4."

thanks
Avatar of rockiroads
rockiroads
Flag of United States of America image

It usually refers to the amount of fields you are adding in does match the table defintion

The INSERT statement must match the fields in the database defintion
Alternatively if you do not want to specify all the fields you can specify what fields to insert into

INSERT INTO TABLE (FieldDef1, FieldDef2...) VALUES (FieldValue1, FieldValue2, ...)

Ok, just thought, it might not be tthe SQL

Try DoCmd.RunSQL

By the way, has your table got AutoNumber?
If so then use the INSERT INTO TABLE (fields) VALUES (values)
this bypasses autonumber - dont worry a number is still generated
Avatar of tonikaram
tonikaram

ASKER

it worked, but now it asks me for every row:

You are about to append 1 row(s). Once you click Yes, you can't use the Undo command to reverse the changes. Are you sure you want to append the selected rows?

since it is an SQL server. How do I remove that?
ASKER CERTIFIED SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

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