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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| Option Compare Database
Option Explicit
'*****************************
'fonction de test d'existence d'une table par les propriétés VBA
'input = nom de la table
'output = booleen
'*****************************
Function DoesTableExist(ByVal NomTable As String) As Boolean
Dim str As String
On Error GoTo NoTable
str = CurrentDb.TableDefs(NomTable).Name
DoesTableExist = True
Exit Function
NoTable:
Select Case err.Number
Case 3265
DoesTableExist = False
End Select
End Function
'*****************************
'fonction de test d'existence d'une table par les requêtes SQL
'input = nom de la table
'output = booleen
'*****************************
Function DoesTableExist2(ByVal NomTable As String) As Boolean
Dim rs As DAO.Recordset
On Error GoTo NoTable
Set rs = CurrentDb.OpenRecordset("SELECT * FROM [" & NomTable & "]")
DoesTableExist2 = True
ExitDoesTable:
Set rs = Nothing
Exit Function
NoTable:
Select Case err.Number
Case 3078
DoesTableExist2 = False
End Select
Resume ExitDoesTable
End Function
Function ViderTable(NomTable As String) As Boolean
On Error GoTo fin
CurrentDb.Execute "DELETE * FROM [" & NomTable & "];"
ViderTable = True
Exit Function
fin:
ViderTable = False
End Function
Function DetruireTable(NomTable As String) As Boolean
On Error GoTo fin
CurrentDb.TableDefs.Delete NomTable
DetruireTable = True
Exit Function
fin:
DetruireTable = False
End Function
Function DetruireTable2(NomTable As String) As Boolean
On Error GoTo fin
DoCmd.DeleteObject acTable, NomTable
DetruireTable2 = True
Exit Function
fin:
DetruireTable2 = False
End Function
Function DetruireTable3(NomTable As String) As Boolean
On Error GoTo fin
CurrentDb.Execute "DROP [" & NomTable & "]"
DetruireTable3 = True
Exit Function
fin:
DetruireTable3 = False
End Function
Function DetruireRequete(NomRequete As String) As Boolean
On Error GoTo fin
CurrentDb.QueryDefs.Delete NomRequete
DetruireRequete = True
Exit Function
fin:
DetruireRequete = False
End Function
Function DetruireRequete2(NomRequete As String) As Boolean
On Error GoTo fin
DoCmd.DeleteObject acQuery, NomRequete
DetruireRequete2 = True
Exit Function
fin:
DetruireRequete2 = False
End Function
Function DetruireEtat(NomEtat As String) As Boolean
On Error GoTo fin
DoCmd.DeleteObject acReport, NomEtat
DetruireEtat = True
Exit Function
fin:
DetruireEtat = False
End Function
Function DetruireFormulaire(NomFormulaire As String) As Boolean
On Error GoTo fin
DoCmd.DeleteObject acForm, NomFormulaire
DetruireFormulaire = True
Exit Function
fin:
DetruireFormulaire = False
End Function
Function PresenceEtat(PathBase As String) As Boolean
Dim Db As DAO.Database
Dim AccAppl As New Access.Application
Dim temp As AccessObject
PresenceEtat = False
With AccAppl
.OpenCurrentDatabase (PathBase)
Set Db = .CurrentDb
End With
For Each temp In AccAppl.CurrentProject.AllReports
Debug.Print "Presence d'état : " & temp.Name
PresenceEtat = True
Exit For
Next
Db.Close
Set AccAppl = Nothing
End Function |
Partager