beenut23
Technical User
- Aug 17, 2008
- 8
Hello. I am having trouble getting my code to add a new record to a subform. Here is the situation. I have a main form frmAddNewCase, which has a subform on it subfrmCaseWitnesses.
When the user clicks the button they first see a msgbox asking them if they want to search for a name first. if they click 'no' in that message box, it opens the form frmWitnessDataEntry to a blank record so they can add a new witness to the database.
The frmWitnessDataEntry has a subform on it as well. The main form contains the Name info and the NameID, and the subform is linked to it in the master and child fields on NameID. The subform contains the SSN, Address, birthdate and contact information for that NameID.
On this frmWitnessDataEntry, I have a button with the following code:
This is supposed to add a new name to the subfrmCaseWitnesses. Currently, if there is already one name on that subform, the code overwrites it with the name entered in the frmWitnessDataEntry.
Can anyone look at my code and tell me how to get it to add a new record to the subform every time?
Oh, and I did try entering a name directly into the subform, and it does allow that, so I know that I can add a new record somehow. Thank you.
When the user clicks the button they first see a msgbox asking them if they want to search for a name first. if they click 'no' in that message box, it opens the form frmWitnessDataEntry to a blank record so they can add a new witness to the database.
The frmWitnessDataEntry has a subform on it as well. The main form contains the Name info and the NameID, and the subform is linked to it in the master and child fields on NameID. The subform contains the SSN, Address, birthdate and contact information for that NameID.
On this frmWitnessDataEntry, I have a button with the following code:
Code:
Private Sub cmdAddWitness_Click()
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
If Me.Dirty Then Me.Dirty = False
Dim NewWitness As String
NewWitness = Me![NameID]
With Forms!frmAddNewCase!subfrmCaseWitnesses
.SetFocus
RunCommand acCmdRecordsGoToNew
.Form.NameID = NewWitness
End With
DoCmd.Close
End Sub
This is supposed to add a new name to the subfrmCaseWitnesses. Currently, if there is already one name on that subform, the code overwrites it with the name entered in the frmWitnessDataEntry.
Can anyone look at my code and tell me how to get it to add a new record to the subform every time?
Oh, and I did try entering a name directly into the subform, and it does allow that, so I know that I can add a new record somehow. Thank you.