>You could do a background renumber on every Delete (there is an event
for that).
Thx Bas ! To be honest it had occurred to me along the way, but I
wanted to bullet-proof the renumbering snippet via a manual button on
the form before tying it into my delete event. I have done that finally
& it sems to work ... just 1 small glitch.
The Glitch:
---------------
If I delete a few or single records the re-numbering works fine ... but
if I delete all records, then the renumbering does not occur. On close
examination I found in the
Sub Cmd_ReNumber_Cl ick, the recordsetclone id sort of disconnected from
the recordset. After deleting ALL records, now even if i add several
records, the condition (rst.BOF And rst.EOF) tests TRUE which leads me
to believe the recordset is getting populated whereas the
recordsetclone has been disconnected from the original recordset. Is
there any way of tying them back together again ?
My code is posted below.
Private Sub Cmd_ReNumber_Cl ick() 'Code Snippet Courtesy of Wayne
Morgan
Dim rst As DAO.Recordset, lngNumber As Long
Set rst = Me.RecordsetClo ne
MsgBox rst.BOF & " " & rst.EOF
If Not (rst.BOF And rst.EOF) Then
With rst
.MoveFirst
lngNumber = 0
Do Until .EOF
lngNumber = lngNumber + 1
.Edit
![Sub_Tran_No] = lngNumber
.Update
.MoveNext
Loop
.Close
End With
End If
Set rst = Nothing
If Me.Recordset.Re cordCount = 0 Then
Me.Sub_Tran_No. DefaultValue = 1
Else
Me.Sub_Tran_No. DefaultValue = DMax("sub_tran_ no", "JVTable") +
1
End If
Me.Refresh
Screen.Previous Control.SetFocu s
End Sub
Private Sub Cmd_Delete_Clic k()
On Error GoTo Err_Cmd_Delete_ Click
DoCmd.SetWarnin gs False
DoCmd.DoMenuIte m acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuIte m acFormBar, acEditMenu, 6, , acMenuVer70
DoCmd.SetWarnin gs True
Me.DrTotal = DSum("DEBIT", "JVTable") ' After deleting a Record
Totals shd be re-calculated
Me.CrTotal = DSum("CREDIT", "JVTable")
Screen.Previous Control.SetFocu s
Call Cmd_ReNumber_Cl ick 'Re-Number the sub_tran_no field if any
record is DELETED
Exit_Cmd_Delete _Click:
Exit Sub
Err_Cmd_Delete_ Click:
MsgBox Err.Description
Resume Exit_Cmd_Delete _Click
End Sub
Private Sub Form_Current()
Dim msg, msg1, msg2, msg3 As String
If Me.NewRecord = True And Me.Sub_Tran_No >= 254 Then
'MsgBox "New Record !"
msg1 = "MAXIMUM ROWS/TRANSACTIONS ALLOWED ARE 255 !" & Chr(13)
& Chr(13)
msg2 = "Please Delete Some Rows !"
MsgBox msg1 & msg2, vbOKOnly + vbCritical, "Error !"
SendKeys "^{PGUP}", True
Screen.Previous Control.SetFocu s
End If
If Me.Recordset.Re cordCount = 0 Then
'MsgBox "Empty Table !"
Me.Sub_Tran_No. DefaultValue = 1
Else
Me.Sub_Tran_No. DefaultValue = DMax("sub_tran_ no", "JVTable") +
1
End If
End Sub
Wayne, thank you for the code.
Best Rgds,
Prakash.