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
| Set rstCompte = New ADODB.Recordset
rstCompte.CursorType = adOpenKeyset
rstCompte.LockType = adLockOptimistic
' Get data from the user.
strCodeCompte = Trim(TxtCodeCompte)
strLibelleCompte = Trim(txtIntitule)
If strCodeCompte = "" Or strLibelleCompte = "" Then
MsgBox "SVP entez le numéro du compte, " & _
" et l'intitulé du compte"
Exit Sub
End If
If strCodeCompte <> "" And strLibelleCompte <> "" Then
' Open COMPTE table.
Set rstCompte = New ADODB.Recordset
rstCompte.CursorType = adOpenKeyset
rstCompte.LockType = adLockOptimistic
'ouverture de la table avec essais d'au moins une entrée deja existante dans la table
rstCompte.Open "COMPTE Where NUM_COMPTE =" & strCodeCompte & " Or LIBELLE = '" & strLibelleCompte & "'", cnn1, , , adCmdTable
If Not rstCompte.EOF Then
' une ligne d'enregistrement correspond a au moins un des 2 champs
Dim Msg$
If rstCompte!NUM_COMPTE = strCodeCompte Then Msg$ = strCodeCompte
If rstCompte!LIBELLE = strLibelleCompte Then
If Msg$ = "" Then
Msg$ = strLibelleCompte
Else
Msg$ = Msg$ & "et " & strLibelleCompte
End If
End If
rstCompte.Close
cnn1.Close
Msg$ = Msg$ & vbCrLf & "existe deja"
MsgBox Msg$, vbCritical, "Doublon"
Exit Sub
End If
End If
'd'ici on est sûr que pas de doublon, pas de prposition vide
rstCompte.Open "COMPTE", cnn1, , , adCmdTable
rstCompte.AddNew
rstCompte!NUM_COMPTE = strCodeCompte
rstCompte!LIBELLE = strLibelleCompte
rstCompte.Update
booRecordAdded = True
' Show the newly added data.
MsgBox "New record: " & rstCompte!NUM_COMPTE & " " & _
rstCompte!LIBELLE & " "
rstCompte.Close
cnn1.Close |
Partager