Comment mettre un numéro de facture par défaut qui s'incrémente automatiquement

titi - 11 sept. 2001 à 23:21
 mds - 15 sept. 2001 à 19:12
Salut,
j'ai un petit pb, je dois modifier le code ci dessous pour qu'un numéro de facture s'affiche automatiquement sous la forme:
F0109014
F:désignant facture
01:l'année 2001
09:le mois de septembre
014:correspond par exemple à la 14ème facture du mois
Donc je voudrais modifier le code suivant pour avoir le résultat ci dessus.

Option Explicit
' Modèle de base VBScript pour masques Commence.n' Reportez-vous à
votre documentation Commence pour en savoir plus sur la mise au point de
scripts.
Const TVA = 19.6
Sub Form_OnLoad()
End Sub
Sub Form_OnSave()
End Sub
Sub Form_OnCancel()
End Sub
Sub Form_OnEnterTab(ByVal TabName)
Dim id
Dim vid
Dim sID
set id = Form.Field("ZINDEX.DOC")
vid = id.value
If vid = "" then
If Len(sID) < 12 Then
sID = RandomLetter(4)
sID = sID & RandomNumber(8)
id.Value = sID
End if
End If
End Sub
Sub Form_OnLeaveTab(ByVal TabName)
End Sub
Sub Form_OnEnterField(ByVal FieldName)
End Sub
Sub Form_OnLeaveField(ByVal FieldName)
If form.field("Type").value = "Devis" then
Dim index
Dim vindex
Dim sIndex
set index = Form.Field("*N° pièce")
vindex = index.value
If vindex = "" then
If Len(sIndex) < 12 Then
sIndex = RandomLetter(1)
sIndex = "F" & sIndex & RandomNumber(4)
index.Value = sIndex
End if
End If
End If
If FieldName = "Est facture de Ligne de document" Then
Call Ligne
' Dim FHT
' Dim VHT
' Set FHT = Form.field("Total HT")
' VHT = FHT.value
' Form.field("Total TTC").value = VHT*TVA
End If
End Sub
Dim vligne ()
Sub Ligne()
Dim CoCount
Dim oxLigne
Set oxLigne = Form.Connection("Est facture de","Ligne de document")
CoCount = oxLigne.ConnectedItemCount
Redim vligne(CoCount - 1)
Dim i
Dim vMht
vMht = 0
Dim Cmc
Set Cmc = CreateObject("Commence.DB")
For i = 1 To CoCount
oxLigne.CurrentSelection = i
vligne(i-1) = oxLigne.ItemName
Dim Crs
Set Crs = Cmc.GetCursor(0,"Ligne de document",0)
Crs.SetFilter "[ViewFilter(1,F,,*N° ligne,Equal To,"+vligne(i-1)+")]",0
Dim NbrItem
NbrItem = Crs.RowCount
Dim Ers
Set Ers = Crs.GetEditRowSet(NbrItem,0)
Dim Mhtidx
Mhtidx = Ers.GetColumnIndex("Total ttc",0)
Dim Fact
Fact = Ers.GetColumnIndex("F",0)
Dim j
For j = 1 To NbrItem
vMht = vMht + Ers.GetRowValue(j-1,Mhtidx,0)
Ers.ModifyRow j-1,Fact,"1",0
Ers.Commit 0
Next
Next
Form.Field("Total TTC").Value = vMht
Set Ers = Nothing
Set Crs = Nothing
Set Cmc = Nothing
End Sub
'Fonction création de ID
Function RandomLetter(ByVal Digits)
Randomize Timer
Dim Rand, i, x, Rand2, y
Dim Index(26)'le code commence à 0 normalement et
'démarre de A
Index(18) = "S"
Index(19) = "T"
Index(20) = "U"
Index(21) = "V"
Index(22) = "W"
Index(23) = "X"
Index(24) = "Y"
Index(25) = "Z"
For i = 1 to Digits
Rand2 = Int((25 - 1 + 1) * Rnd + 1)
RandomLetter = RandomLetter & Index(Rand2)
Next
End Function
Function RandomNumber(ByVal Digits)
RandomNumber = ""
Randomize Timer
Dim Rand
Dim i
For i = 1 to Digits
Rand = Rand & Int(Rnd * 9)
Next
RandomNumber = Rand
End Function
Je remercie d'avance les personnes qui pourront m'apporter de l'aide
MATHIEU
A voir également:

1 réponse

Je n 'ai pas bien compris l'objet de ta demande.
Il y a bien trop de lignes de code, pour le résultat
qu tu sembles vouloir obtenir - (dans la mesure ou il
s'agit bien de cela), je te propose de faire quelque
chose de ce genre.

Private Sub Form_Load()
MsgBox NumFact(225, "05/25/2001")
End Sub

Public Function NumFact(NuméroFacture As Integer, Optional Dates As String) As String

Dim Mois As Integer If Dates "" Then Dates Date$

'Si le format Dates est Américan (mmjjaaaa)
Mois = Val(Left(Dates, 2))
'NumFact = "F" & Right$(Dates, 2) & Left$(Dates, 2) & Format$(NuméroFacture, "0000")

'Si le format Dates est Européen (jjmmaaaa)
'NumFact = "F" & Right$(Dates, 2) & Mid$(Dates, 3, 2) & Format$(NuméroFacture, "0000")
'Mois = Val(Mid$(Dates, 3, 2))

'Variante !
'MonthName(Mois, False)
NumFact = "F" & Right$(Dates, 2) & UCase(MonthName(Mois, True)) & Format$(NuméroFacture, "0000")

End Function
0
Rejoignez-nous