Insert New Record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need the code to insert a new record in a table that is in the same .mdb
database that my form is in, I want a command button that on click will
insert a record into a table called POINTS

The POINTS table has 2 fields called NAME_ID and SCORE - both are number
fields and for testing purposes I want bot to get a value of 1 inserted when
the record is created.
 
tiredoftrying said:
I need the code to insert a new record in a table that is in the same
.mdb database that my form is in, I want a command button that on
click will insert a record into a table called POINTS

The POINTS table has 2 fields called NAME_ID and SCORE - both are
number fields and for testing purposes I want bot to get a value of 1
inserted when the record is created.

Here's one way:

CurrentDb.Execute _
"INSERT INTO POINTS (NAME_ID, SCORE) " & _
"VALUES(1, 1)", _
dbFailOnError
 
very helpful - but one more question, using the code you provided what if I
wanted to use fields on my form that has the values in them to populate the
new record
 
tiredoftrying said:
very helpful - but one more question, using the code you provided
what if I wanted to use fields on my form that has the values in them
to populate the new record

Assuming both fields are numeric, as you said:

CurrentDb.Execute _
"INSERT INTO POINTS (NAME_ID, SCORE) " & _
"VALUES(" & Me!txtNameID & ", " & Me!txtScore & ")", _
dbFailOnError

where "txtNameID" and "txtScore" are the names of the controls on your
form.
 
Back
Top