In an Access 2003 database, I've created a button on a form that opens a subform in a popup window, linked to the parent form via the ClaimAutoID field (the underlying tables for the form and the subform are also linked via this field). The code for this is as follows:
Private Sub AddNewNoteCmd_Click()
On Error GoTo Err_AddNewNoteCmd_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Add New Note"
stLinkCriteria = "[ClaimAutoID] = " & Me.ClaimAutoID
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord , , acNewRec
The code that links the popped up subform to the parent form via the ClaimAutoID works fine, in that the records you see if you scroll through entries in the subform are only the records that are related to the current record on the parent form. However, when you save a new record on this subform, it gets saved without any data in the ClaimAutoID field, so the new record that get saved are no longer linked to the current record in the parent form. To deal with this I've created a "Save" button on the subform which is supposed to insert the value in the ClaimAutoID field from the current record on the parent form into the ClaimAutoID field for the current record being saved in the subform. The ClaimAutoID field is not visible in the subform. Here is the code:
Private Sub SaveNote_Click()
On Error GoTo Err_SaveNote_Click
Dim strSQL As String
strSQL = "INSERT Into tblClaims_Notes (ClaimAutoID) VALUES (Me.ClaimAutoID)"
CurrentDb.Execute strSQL, dbFailOnError
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
When I click on this save button, I get the error "Too few parameters. Expected 1". Can someone please tell me what I'm doing wrong? Any help is greatly appreciated.