Option Explicit
Public Cn As Object
Public Sub ConnexionAccess()
Dim cheminAcces As String
' Chemin complet de la base Access
cheminAcces = bureau & "\superette2025\superette2025.accdb"
' Création de l'objet ADODB.Connection
Set Cn = CreateObject("ADODB.Connection")
Cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & cheminAcces & ";Jet OLEDB:Database Password=;"
' Ouverture de la connexion
On Error GoTo ErreurConnexion
MsgBox "Connexion réussie à la base de données.", vbInformation
Exit Sub
Sql = "SELECT * FROM Produit WHERE Code_Barre='" & TxTCodeBarre.Text & "'"
With Cn.execut(Sql)
If Not .EOF Then
TxTNomProduit.Text = "" & !Nom_Produit
TxTPrixVente.Text = "" & !Prix_Vente
TxtQuantite.Text = "1"
LstNouvelleVente.AddItem "" & !Code_Barre
LstNouvelleVente.List(LstNouvelleVente.ListCount - 1, 1) = "" & !Nom_Produit
LstNouvelleVente.List(LstNouvelleVente.ListCount - 1, 2) = "" & !Prix_Vente
LstNouvelleVente.List(LstNouvelleVente.ListCount - 1, 3) = TxtQuantite.Text
End With
Else
MsgBox "Produit introuvable", vbExclamation
End If
.Close
End With
with
ErreurConnexion:
MsgBox "Erreur de connexion : " & Err.Description, vbCritical
End Sub
Function bureau() As String
With CreateObject("Shell.Application")
bureau = .Namespace(&H10&).Self.Path ' &H10 = Desktop folder
End With
End Function