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
| Public Sub AddNewCompte()
Dim cnn1 As ADODB.Connection
Dim rstCompte As ADODB.Recordset
Dim strCnn As String
Dim strCodeCompte As String
Dim strLibelleCompte As String
Dim booRecordAdded As Boolean
' Open a connection.
Set cnn1 = New ADODB.Connection
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Compta_v4.mdb;Persist Security Info=False"
cnn1.Open strCnn
' Open COMPTE table.
Set rstCompte = New ADODB.Recordset
rstCompte.CursorType = adOpenKeyset
rstCompte.LockType = adLockOptimistic
rstCompte.Open "COMPTE", cnn1, , , adCmdTable
' Get data from the user.
strCodeCompte = Trim(TxtCodeCompte)
strLibelleCompte = Trim(txtIntitule)
' Proceed only if the user actually entered something
' for both the CodeCompte and LibelleCompte.
If (strCodeCompte <> "") Then
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 & " "
Else
MsgBox "SVP entez le numéro du compte, " & _
" et l'intitulé du compte"
End If
' Delete the new record because this is a demonstration.
'cnn1.Execute "DELETE FROM employee WHERE emp_id = '" & strCodeCompte & "'"
rstCompte.Close
cnn1.Close
End Sub |
Partager