Adding a new record in code

  • Thread starter Thread starter Jack G
  • Start date Start date
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
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top