Adding a new record in code

J

Jack G

Seems like this should be really basic, but I'm having trouble. I want to
add a new record through code, and I've tried the following without success
(the strings "A1205" and "Test" are for testing purposes -- the strings will
actually be derived in the code):

DoCmd.OpenTable "XNumbers", , acAdd
Tables.XNumbers.XProjectNumber = "X1205"
Tables.XNumbers.Description = "Test"

or

DoCmd.OpenQuery "XQuery"
DoCmd.RunCommand acCmdRecordsGoToNew
Queries.XQuery.XProjectNumber = "X1205"
Queries.XNumbers.Desscription = "Test"

Could anyone steer me in another direction?

Thanks,

Jack
 
K

Klatuu

Here is how it is really done:

Dim strSQL As String

strSQL = "INSERT INTO XNumbers (ProjectNumber, Description) Values('" &
Me.txtProjectNumber & "', '" & Me.Description & "');"
CurrentDb.Execute(strSQL), dbFailOnError
 
J

Jack G

Thanks, Klatuu! That works great.

Jack

Klatuu said:
Here is how it is really done:

Dim strSQL As String

strSQL = "INSERT INTO XNumbers (ProjectNumber, Description) Values('" &
Me.txtProjectNumber & "', '" & Me.Description & "');"
CurrentDb.Execute(strSQL), dbFailOnError
 
Top