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
| Private Sub Form_Open(Cancel As Integer)
' ...
swModif = False ' avant toute modification
End Sub
Private Sub Form_Dirty(Cancel As Integer)
swModif = True ' il y a eu modification
End Sub
Private Sub ctlPwd_AfterUpdate()
Me.cmdExit.SetFocus
cmdExit_Click
End Sub
Private Sub cmdExit_Click()
On Error GoTo Err_cmdExit_Click
If swModif = False Then ' aucune modification
DoCmd.Close
Exit Sub
End If
If Me.Dirty Then ' enregistrement modifié
DoCmd.RunCommand acCmdSaveRecord ' à sauver
End If
nbActive = DCount("blnActive", "qselfrmManageLinks", "[blnActive]=On")
If nbActive <> 1 Then
MsgBox "Une seule base active, svp, ni plus ni moins !", _
vbOKOnly, "Sélection"
Else
nbProtected = DCount("blnProtected", "qselfrmActiveDB", _
"[blnProtected]=On")
If nbProtected Then ' la base DATA choisie est protégée
strPassword = ""
If IsNull(Me.ctlPwd) Then ' mot de passe pas donné
If Me.ctlPwd.Visible = False Then ' pas encore
MsgBox "La base Data de l'application choisie " & _
"est protégée !" & vbCrLf & "Mot de passe requis" _
& vbCrLf & "Abandon en tapant EXIT", _
vbInformation, "Validation"
Me.ctlPwd.Visible = True
Me.ctlPwd.SetFocus
End If
Exit Sub
Else
strPassword = Me.ctlPwd
blnPasswordOK = True
Me.ctlPwd.Visible = False
End If
End If
DoCmd.Close
End If
Exit_cmdExit_Click:
Exit Sub
Err_cmdExit_Click:
MsgBox Err.Description
Resume Exit_cmdExit_Click
End Sub '--------------------------------------------------------------------
Private Sub Form_Unload(Cancel As Integer) ' avant le Close effectif
If swModif = False Then
Exit Sub
End If
If strPassword = "EXIT" Then
MsgBox "Il faudra recommencer le choix de " _
& "l'application !" & vbCrLf & "Les liaisons" & _
" n'ont pu être actualisées", , "Abandon"
Else
Forms![fmnuMenu].RecordSource = "qselfrmActiveDB"
' indispensable pour afficher la bonne DATA DB
aApp = Forms![fmnuMenu]![ctlAPPpath] '
If aApp <> CurApp Then ' changement d'application
AttachTables (aApp)
If swAttach = False Then
MsgBox "Les liaisons n'ont pu être actualisées", _
, "Abandon"
Cancel = True
End If
End If
End If
End Sub '--------------------------------------------------------------------
Sub AttachTables(DB_name As String)
Dim DB As DAO.Database
Dim td As TableDef
Dim I As Integer, sw As Long, newPath As String
On Error GoTo Err_AttachTables
swAttach = False
newPath = ""
DoCmd.Hourglass True
If blnPasswordOK Then ' mot de passe nécessaire et donné
newPath = "MS Access;PWD=" & strPassword
End If
newPath = newPath & ";DATABASE=" & DB_name
Set DB = CurrentDb()
For I = 0 To DB.TableDefs.Count - 1
Set td = DB.TableDefs(I)
sw = (td.Attributes And DB_ATTACHEDTABLE) ' local/attached table ?
If (td.Name <> "AttachedDB" And td.Name <> "tblParamètre") Then
' skip the link management and parameter (ReDimPos) tables
If (sw <> 0) Then ' skip local tables
If (td.Connect <> "") Then ' with a connect string ?
td.Connect = newPath
td.RefreshLink
End If
End If
End If
Next I
swAttach = True
Exit_AttachTables:
DoCmd.Hourglass False
Exit Sub
Err_AttachTables:
MsgBox Err.Number & " " & Err.Description & " " & td.Name _
& vbCrLf & newPath
Resume Exit_AttachTables
End Sub '-------------------------------------------------------------------- |
Partager