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 44 45 46 47 48 49 50 51 52 53 54 55
|
Sub TesterPourVoir()
Dim strSemNo As String
Dim lngSemNo As Long
Dim vntGroupID As Variant
Dim lngAjouts As Long
strSemNo = InputBox("Quel numéro de semaine ?", "Semaine N°", DatePart("ww", Now))
vntGroupID = InputBox("Quel numéro de groupe ?", "Identifiant groupe")
If IsNumeric(strSemNo) Then
lngSemNo = CLng(strSemNo)
If Len(vntGroupID) Then
If AjouterAchats(lngSemNo, vntGroupID, lngAjouts) Then
MsgBox lngAjouts & " ligne(s) d'achat ont été intégrée(s) pour le groupe " & vntGroupID, vbInformation
End If
End If
End If
End Sub
Private Function AjouterAchats(ByVal SemNo As Long, ByVal GroupID As Variant, ByRef NombreAjouts As Long) As Boolean
Dim oDB As DAO.Database
Dim oRS As DAO.Recordset
Dim strNomCli As String
Dim SQLClient As String
Dim SQLAchat As String
On Error GoTo L_ErrAjouterAchats
Set oDB = CurrentDb
SQLClient = "SELECT Nom, Prénom, Groupe FROM CLIENT WHERE Groupe = " & GroupID & ";"
Set oRS = oDB.OpenRecordset(SQLClient, 2)
With oRS
Do While Not .EOF
strNomCli = .Fields(0).Value
'La quantité reste null
SQLAchat = "INSERT INTO ACHAT (Nom, Groupe, NumSemaine, Quantité) "
SQLAchat = SQLAchat & "VALUES ('" & strNomCli & "'," & GroupID & ", " & SemNo & ", NULL)"
oDB.Execute SQLAchat, dbConsistent
NombreAjouts = NombreAjouts + 1
.MoveNext
Loop
.Close
End With
AjouterAchats = True
On Error GoTo 0
L_ExAjouterAchats:
Set oRS = Nothing
Set oDB = Nothing
Exit Function
L_ErrAjouterAchats:
AjouterAchats = False
MsgBox Err.Description, 48, Err.Source
Resume L_ExAjouterAchats
End Function |
Partager