1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim oRst As DAO.Recordset
If Me.NewRecord Then
Set oRst = CurrentDb.OpenRecordset("SELECT Max(indice) FROM tblFacture WHERE Format(datefact,""yyyy"")=" & Chr(34) & Format(Me.datefact, "yyyy") & Chr(34))
With oRst
If Not .EOF Then
Me![indice].Value = Nz(.Fields(0).Value, 0) + 1
Else
Me![indice].Value = 1
End If
.Close
End With
End If
If IsNull(Me.indice.Value) Then
Me.indice.Value = Format(Nz(DMax("[indice]", "[tblFacture]", "Year([datefact])='" & Year([datefact]) & "'"), 0) + 1)
End If
Me.numfact.Value = "FAC-" & Year([datefact]) & "-" & Format([datefact], "mm") & "-" & Format([indice], "000")
End Sub |