Here's a slightly different coding convention, with the whole code from behind one of my command buttons.
To add this kind of code behind a button,
1) look at the form in design view,
2) right click the command button,
3) open the properties pane,
4) switch to the events tab,
5) click in the box for the CLICK event,
6) click the three dots to the right of the box,
7) and select code builder.
The VB editor will start you with a stub of code.
8) Copy this code in its place.
Code:
Private Sub cmdAddAll_Click()
On Error GoTo Err_cmdAddAll_Click
Dim strSQL As String
Dim intItem As Integer
Dim listChanged As Boolean
' turn off warnings for updates
DoCmd.SetWarnings False
' build sql
strSQL = "INSERT INTO tblYourTable ( [FieldName1], [FieldName2] ) " _
& "VALUES ( Value1, Value2 ); "
' for testing, show SQL
' MsgBox strSQL
' run sql
DoCmd.RunSQL strSQL
' turn on warnings for updates
DoCmd.SetWarnings True
' redisplay
Me.Requery
Exit_cmdAddAll_Click:
Exit Sub
Err_cmdAddAll_Click:
MsgBox Err.Description
Resume Exit_cmdAddAll_Click
End Sub
9) Change the name of the command button in the above code to match yours (use global replace). In this example, the button name was cmdAddAll.
10) Replace the SQL with your own.
11) You might want to uncomment the Msgbox statement to see what youre SQL looks like before it executes.
12) switch the form back to form view and click the button.
If this doesn't work, please post your code here and describe exactly what happened when you clicked the button. If it does work, please mark the thread solved.