Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert Into two tables values from a form

Status
Not open for further replies.

UNDPC

MIS
Dec 18, 2003
57
US
Hi,
When clicking a command button, I am trying to run VBA code to Insert the data from two fields on my form into two separate tables. I though I might have the code correct, but after I ran it, and checked the tables, the new records were not there. Here is my code, I hope someone can help. Thanks.

Private Sub cmd_Join_SAK_Insert_Click()

On Error GoTo Err_cmd_Join_SAK_Insert_Click

DoCmd.GoToRecord , , acNewRec

Exit_cmd_Join_SAK_Insert_Click:
Exit Sub

Err_cmd_Join_SAK_Insert_Click:
MsgBox Err.Description
Resume Exit_cmd_Join_SAK_Insert_Click

CurrentDb.Execute "INSERT INTO tbl_join_SAK ( [S-A ID], [Key Control ID] ) VALUES (" & [Forms]![frm_relationships_SAK]![ID] & "," & [Forms]![frm_relationships_SAK]![Key Control ID] & ");"

CurrentDb.Execute "INSERT INTO join_SAK2 ( [S-A ID], [Key Control ID] ) VALUES (" & [Forms]![frm_relationships_SAK]![ID] & "," & [Forms]![frm_relationships_SAK]![Key Control ID] & ");"


End Sub
 
Well, what I see is that you have gone to a new record before your Insert statements which will have no values in the two fields you are trying to insert into your tables. Also, your syntax says that [ID] and [Key Control Id] are both number fields. You should confirm that that is correct.
Try commenting out the Docmd.Go To Record line and see if it works.

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top