G
Gordon Foster
Hi,
I have a form with a subform on it. In the AfterUpdate event of a control
on the subform I do a check and if necessary I add a new record to the main
form. For some reason I noticed that the field I have in the main forms
table with a Data Type of AutoNumber is incrementing by 2 instead of 1 which
leads me to believe I have done something wrong. Visually from the form it
looks like it's working okay but I still think something is wrong. Here is
the code for the AfterUpdate event:
Private Sub colour_AfterUpdate()
Dim str As String
'save current record in subform so recordcount calculates properly
Me.Dirty = False
'if there are 2 records in the subform
If Me.RecordsetClone.RecordCount = 2 Then
'get the value of a field from the parent form
str = Me.Parent!field1
'add a new record to the parent form
Me.Parent.Recordset.AddNew
'set the value of the field on the parent form to what was saved
Me.Parent!field1 = str
'save the parent's record, this I am doing since the cursor is left on
the subform ready for data
'entry and ensures that there is a saved record on the one side of the
one-to-many relationship
Me.Parent.Dirty = False
End If
End Sub
Does this code look okay or should I be doing it a different way? This is
actually from a small sample database I made to ask this question, the real
database adds a record to the parent form in a similar way but the parent
form itself is a subform of yet another form which I don't think should make
a difference.
Any help would be appreciated,
Gordon Foster
I have a form with a subform on it. In the AfterUpdate event of a control
on the subform I do a check and if necessary I add a new record to the main
form. For some reason I noticed that the field I have in the main forms
table with a Data Type of AutoNumber is incrementing by 2 instead of 1 which
leads me to believe I have done something wrong. Visually from the form it
looks like it's working okay but I still think something is wrong. Here is
the code for the AfterUpdate event:
Private Sub colour_AfterUpdate()
Dim str As String
'save current record in subform so recordcount calculates properly
Me.Dirty = False
'if there are 2 records in the subform
If Me.RecordsetClone.RecordCount = 2 Then
'get the value of a field from the parent form
str = Me.Parent!field1
'add a new record to the parent form
Me.Parent.Recordset.AddNew
'set the value of the field on the parent form to what was saved
Me.Parent!field1 = str
'save the parent's record, this I am doing since the cursor is left on
the subform ready for data
'entry and ensures that there is a saved record on the one side of the
one-to-many relationship
Me.Parent.Dirty = False
End If
End Sub
Does this code look okay or should I be doing it a different way? This is
actually from a small sample database I made to ask this question, the real
database adds a record to the parent form in a similar way but the parent
form itself is a subform of yet another form which I don't think should make
a difference.
Any help would be appreciated,
Gordon Foster