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 56 57 58
| Public Sub UpdateCompte()
Dim cnn1 As ADODB.Connection
Dim rstCompte As ADODB.Recordset
Dim strCnn As String
Dim booRecordAdded As Boolean
Dim strOldFirst As String
Dim strOldLast As String
Dim strMessage As String
Dim strCodeCompte As String
Dim strLibelleCompte As String
' Open a connection.
Set cnn1 = New ADODB.Connection
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\dahmani\Bureau\Nouveau dossier (2)\compta_v4.mdb;Persist Security Info=False"
cnn1.Open strCnn
Set rstCompte = New ADODB.Recordset
rstCompte.CursorType = adOpenKeyset
rstCompte.LockType = adLockOptimistic
rstCompte.Open "SELECT NUM_COMPTE, LIBELLE " & _
"FROM COMPTE ORDER BY NUM_COMPTE", strCnn, , , adCmdText
' Store original data.
strOldFirst = rstCompte!NUM_COMPTE
strOldLast = rstCompte!LIBELLE
' Change data in edit buffer.
rstCompte!NUM_COMPTE = Trim(TxtCodeCompte)
rstCompte!LIBELLE = Trim(txtIntitule)
' Show contents of buffer and get user input.
strMessage = "Edit in progress:" & vbCr & _
" Original data = " & strOldFirst & " " & _
strOldLast & vbCr & " Data in buffer = " & _
rstCompte!NUM_COMPTE & " " & rstCompte!LIBELLE & vbCr & vbCr & _
"Use Update to replace the original data with " & _
"the buffered data in the Recordset?"
If MsgBox(strMessage, vbYesNo) = vbYes Then
rstCompte.Update
Else
rstCompte.CancelUpdate
End If
' Show the resulting data.
MsgBox "Data in recordset = " & rstCompte!NUM_COMPTE & " " & _
rstCompte!LIBELLE
rstCompte.Close
End Sub |
Partager