I have a subform that I am entering records related to the ClientID on the main form. It creates an extra blank entry when i enter the line prior. How do i stop it from doing that. Image attached.
Can we assume you aren’t referring to the line at the bottom that displays default values but isn’t a new record until you modify any field in the bottom line?
1. Make the subform AllowAdditions property = False.
2. Add a button to the main form called something like 'cmdAddNew'
3. Add the following code to the button click event:
Code:
Private Sub cmdAddNew_Click()
' Make sure you use the name of the subform CONTROL
' - it may be different from the name of the subform used as its SourceObject
Me.NameOfSubformControl.Form.AllowAdditions = True
End Sub
4. Add the following code to your subform's AfterInsert event:
Code:
Private Sub Form_AfterInsert()
Me.AllowAdditions = False
End Sub
When you load the form the blank line won't be there.
When you click cmdAddNew the new line will appear for data entry.
When you start adding the new record another new empty line will appear below it - you will have to live with this!
(Also, you will have to write more code to deal with when the user decides they didn't want to add a new record after all, but I'll leave that up to you!)
When you have finished entering the data and tab out of the record then the additional new empty row will disappear again.
Quite a lot of work for a not perfect solution - you are probably better off just putting up with the empty line waiting there ready for your next record entry!
What do mean by "enter the line prior"? There are six records entered into the subform and the blank (add new) record line is for entering in another record. If you look at your table it should have only the six new records that you entered in the subform and that's it. Are you saying an addition blank record is getting created in the table? There are no blank entries in your screenshot, just the add new record line.