Private Sub impression()
Set cnx = CreateObject("ADODB.Connection")
Dim chemin As String
'chemin est un nom que vous devez associer à une cellule dans
'Excel
Application.Goto Reference:="chemin"
'permet de se positionner sur la cellule se nommant chemin
chemin = ActiveCell 'active la cellule en question
' Nous testons si le fichier est accessible
If Len(Dir(chemin)) > 0 Then
' Déclaration de la variable de connexion
'Définition du pilote de connexion
cnx.Provider = "Microsoft.ACE.OLEDB.12.0;"
'Définition de la chaîne de connexion
cnx.ConnectionString = chemin
'Ouverture de la base de données
cnx.Open
Else
MsgBox "La base n'a pas pu être trouvée" & vbCrLf & _
chemin & vbCrLf & _
"n'est pas un chemin valide.", vbCritical + vbOKOnly
End If
Dim nom_rapport As String
Dim no_requete As Integer
Dim access As access.Application
Set access = New access.Application
access.OpenCurrentDatabase filepath:=chemin
'nom de mon état
nom_rapport = "État_Frm_modif_status"
access.DoCmd.OpenReport nom_rapport, acViewPreview, , "[États]![État_Frm_modif_status]![No_requetes] =13", acWindowNormal
access.DoCmd.RunCommand acCmdReportView
'access.DoCmd.RunMacro "Macro1"
'je quitte Access
access.Quit
Set access = Nothing
End Sub
Sub Lecture() Dim oCon As New ADODB.Connection Dim oRs As New ADODB.Recordset With oCon .ConnectionString = "DSN=MS Access Database;DBQ=" & ActiveWorkbook.Path & "\bdd.accdb" 'adapter chemin base access .Open End With oRs.Open "select * from Contact", oCon, adOpenDynamic, adLockBatchOptimistic 'adapter nom table oRs.Close oCon.Close Set oRs = Nothing Set oCon = Nothing End Sub Sub Ecriture() Dim oCon As New ADODB.Connection Dim oRs As New ADODB.Recordset With oCon .ConnectionString = "DSN=MS Access Database;DBQ=" & ActiveWorkbook.Path & "\bdd.accdb" 'adapter chemin base access .Open End With oRs.Open "select * from Contact", oCon, adOpenDynamic, adLockBatchOptimistic 'adapter nom table With oRs .AddNew .Fields("NOM") = TextBox1 .Fields("Prénom") = TextBox2 .Fields("Adresse") = TextBox3 .Fields("Ville") = TextBox4 .Fields("Code postal") = TextBox5 End With oRs.UpdateBatch oRs.Close oCon.Close Set oRs = Nothing Set oCon = Nothing End Sub
access.DoCmd.OpenReport nom_rapport, acViewPreview, , "[États]![État_Frm_modif_status]![No_requetes] =13", acWindowNormal
access.OpenCurrentDatabase filepath:=chemin
access.visible = true 'Permet de faire afficher l'état à l'écran