what is the code for deleting a new record?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have different subforms inside a form, while 2nd subform depends on the
number indicating on the 1st subform. That is, if there exists the number
"1", there should be only 1 record in the 2nd subform. I've already
constrained it with the following code:

Private Sub Seg__AfterUpdate()
If Me.Seg_ > [Forms]![PROJECT_Information]![Segments] Then
MsgBox "The maximum segment number can not be greater than the project's
segment number!"
End If
End Sub

but when I enter a "2" in the new record "Seg_", the new record exists for
user to enter data, that there are 3 rows (with 2 empty record) instead of
only 1 record that i want. What code should I insert in order to delete the
empty records (row) ? I also want to prevent people to insert anything except
for the correct number, can I make it to delete the new record when the error
message is shown?
Thank you everyone!
 
I have different subforms inside a form, while 2nd subform depends on the
number indicating on the 1st subform. That is, if there exists the number
"1", there should be only 1 record in the 2nd subform. I've already
constrained it with the following code:

Private Sub Seg__AfterUpdate()
If Me.Seg_ > [Forms]![PROJECT_Information]![Segments] Then
MsgBox "The maximum segment number can not be greater than the project's
segment number!"
End If
End Sub

but when I enter a "2" in the new record "Seg_", the new record exists for
user to enter data, that there are 3 rows (with 2 empty record) instead of
only 1 record that i want. What code should I insert in order to delete the
empty records (row) ? I also want to prevent people to insert anything except
for the correct number, can I make it to delete the new record when the error
message is shown?
Thank you everyone!

I'd recommend using the second subform's BeforeInsert event instead;
set its Cancel argument to True (with a user warning) *before* the
record is added, rather than letting the user add one and then
slapping their hand afterward.

John W. Vinson[MVP]
 
Back
Top