1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
Private Sub générer_Click()
Dim Lig As ListRow
Dim Cel As Range
Dim Num As Integer
Dim I As Long
Dim no_ordre As String
'// contrôles saisie
If Me.Mois = Empty Then MsgBox "Mois absent ": Exit Sub
If Me.Qté_demandée = Empty Then MsgBox "Quantité absente ": Exit Sub
If Me.Date_impression = Empty Then MsgBox "Date impression absente ": Exit Sub
'la date doit être valide, la quantité doit être numérique et au minimum à 1
If Not IsDate(Date_impression.Text) Then MsgBox "Date impression non valide !": Exit Sub
If Not IsNumeric(Me.Qté_demandée.Text) Then MsgBox "Seulement numérique !": Exit Sub
If CInt(Me.Qté_demandée.Text) < 1 Then MsgBox "La quantité doit être supérieure à 0 !": Exit Sub
With BD
'si la base n'est pas vide, effectue la recherche pour définir le numéro
If Not .DataBodyRange Is Nothing Then
Set Cel = .ListColumns("N° de série").DataBodyRange.Find(Right(Année.Text, 2) & Format(Mois.Text, "00") & "C01", , xlValues, xlPart)
If Not Cel Is Nothing Then Num = Right(.ListColumns("N° de série").DataBodyRange(Cel.Row - 1).Value, 5)
End If
'crée les références
For I = 1 To Int(Qté_demandée.Text)
Set Lig = .ListRows.Add
no_série = Right(Année.Text, 2) & Format(Mois.Text, "00") & "C01" & Format(Num + I, "00000")
Lig.Range(, 2).Value = no_série
Lig.Range(, 3).Value = CDate(Date_impression.Text)
Next I
End With
End Sub |
Partager