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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help adding new record to subform

Status
Not open for further replies.

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:

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.
 
Perhaps this ?
[!]DoCmd.[/!]RunCommand acCmdRecordsGoToNew

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hello PHV. thank you kindly for your reply. Trying your suggestion, but unfortunately it still does not add the new witness to a new record on the frmAddNewCase.subfrmCaseWitnesses but instead overwrites whichever record on that subform the cursor was on when the user clicks the add new witness button.
 
How about:

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
     DoCmd.GoToRecord , , acNewRec
    .Form.NameID = NewWitness
 End With

DoCmd.Close
   
End Sub
 
Hello, thank you for your reply. no, this still overwrites the existing record on the subform. This is so wierd. why won't it write a NEW record to my subform? very very confused.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top