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
| Private Sub RechGlob_AfterUpdate()
' Recherche dans la base ouverte
DoCmd.OpenForm "formgen", , , "affectation like forms.formAccueil.rechglob"
If IsNull(Forms.formgen.Affectation) Then
DoCmd.Close
Else
Exit Sub
End If
' Recherche dans les autres bases
Dim autreBdd As Access.Application
Set autreBdd = CreateObject("Access.Application")
Const StrFolder = "C:\REPPBX_Base\"
Dim StrFile, StrComplet, StrRechGlob, monsql, monsql2 As String
Dim rst As DAO.Recordset
Dim v As Variant
Dim i As Integer
i = 0
StrFile = Dir(StrFolder & "*.*")
Do While StrFile <> ""
StrFile = Dir
'i = i + 1
MsgBox "fichier = " & StrFile
If Left$(StrFile, 3) = "PN_" Then
GoTo suite
End If
'MsgBox "Folder = " & StrFolder
'MsgBox "fichier = " & StrFile
If LCase(StrFile) Like "*.mdb" Or LCase(StrFile) Like "*.accdb" Then
StrComplet = StrFolder & StrFile
StrRechGlob = Forms.formAccueil.RechGlob
'MsgBox "chemin complet = " & StrComplet
'MsgBox "RechGlob = " & Forms.formAccueil.RechGlob
'MsgBox "StrRechGlob = " & StrRechGlob
monsql2 = "SELECT TabGen.Affectation FROM TabGen IN " & "'" & StrComplet & "'" & " WHERE TabGen.Affectation like " & "'" & StrRechGlob & "'"
Set rst = CurrentDb.OpenRecordset(monsql2, dbOpenDynaset)
v = rst.Fields("affectation")
'If DCount("affectation", (monsql2)) = 1 Then
If v = StrRechGlob then
With autreBdd
.Visible = False
.OpenCurrentDatabase StrComplet
End With
monsql = "UPDATE TabTempGlob IN " & "'" & StrComplet & "'" & " SET TabTempGlob.Affectation = " & "'" & StrRechGlob & "'"
DoCmd.RunSQL monsql
With autreBdd
.DoCmd.OpenForm "FormTempGlob", , , , , acHidden
.Visible = True
.DoCmd.OpenForm "FormGen", , , "affectation like forms.FormTempGlob.affectation", , acWindowNormal
End With
'If IsNull(autreBdd.Forms!formgen!Affectation) Then
'autreBdd.DoCmd.CloseDatabase
'End If
End If
End If
suite:
If i > 3 Then
Exit Sub
End If
Loop
End Sub |
Partager