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
| '------------------------------------------------------------
' Accueil
'
'------------------------------------------------------------
Function Accueil()
On Error GoTo Accueil_Error
Dim strDBCursorType As String
Dim strDBLockType As String
Dim strDBOptions As String
Dim db As DAO.Database
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim i As Long
strDBCursorType = adOpenDynamic 'CursorType
strDBLockType = adLockOptimistic 'LockType
strDBOptions = adCmdText 'Options
Set db = CurrentDb
Set cn = New ADODB.Connection
cn.Open ConnectionString()
With cn
.CommandTimeout = 0
.CursorLocation = adUseClient
End With
Set rs = New ADODB.Recordset 'Création d'un record set
strSQL = "SHOW TABLES FROM " & DatabaseName() & ";" 'Récupération de la liste des tables de la base MySQL
rs.Open strSQL, cn, strDBCursorType, strDBLockType, strDBOptions
If rs.EOF Then
GoTo ExitSub
Else
Do While Not rs.EOF
If TableExiste(rs(0)) Then 'On supprime la table si elle existe déjà
db.TableDefs.Delete (rs(0))
End If
If Left(rs(0), 2) <> "v_" Then 'Je ne lie pas les vues
Lier_table db, rs(0), rs(0)
End If
rs.MoveNext
Loop
End If
ExitSub:
Set rs = Nothing
Set cn = Nothing
Set db = Nothing
Application.RefreshDatabaseWindow ' Actualisation de la fenêtre base de données
On Error GoTo 0
Exit Function
Accueil_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ")"
End Function
'------------------------------------------------------------
' Lier_table
'
'------------------------------------------------------------
Function Lier_table(db As DAO.Database, strSourceTable As String, strTable As String)
Dim td As DAO.TableDef
Set td = db.CreateTableDef(strTable) ' Création nouvelle définition de table
td.Connect = ConnectDAO() ' Chaîne de connexion ODBC pour DAO
td.SourceTableName = strSourceTable ' Nom de la table source
db.TableDefs.Append td ' Ajouter à la collection
Set td = Nothing
End Function |
Partager