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
|
Option Compare Database
Option Explicit
Public Sub ImporterEtat(strChemin As String, strNomEtat As String)
'StrChemin correspond au chemin du fichier MDE
'StrNomEtat correspond au nom de l'état
Dim AppAccess As New Access.Application
Dim oRptSource As Access.Report, oRptDest As Access.Report
Dim oCtlSource As Control
Dim I As Integer
'Ouvre le fichier mde
AppAccess.OpenCurrentDatabase strChemin
'Ouvre l'état en mode aperçu
AppAccess.DoCmd.OpenReport strNomEtat, acViewPreview
'Atteint l'objet Etat
Set oRptSource = AppAccess.Reports(strNomEtat)
'Crée le nouvel état dans la base de données courant
Set oRptDest = CreateReport
'Fixe les mêmes propriétés
DupliqueProprietes oRptSource, oRptDest
'Parcours les controls
For Each oCtlSource In oRptSource.Controls
CreerControle oRptDest.Name, oCtlSource
Next oCtlSource
'Engregistre l'état
DoCmd.Save acReport, oRptDest.Name
'ferme l'état source
AppAccess.DoCmd.Close acReport, strNomEtat, acSaveNo
'Ferme le mde
AppAccess.DoCmd.Quit
'Libère la mémoire
Set AppAccess = Nothing: Set oRptDest = Nothing: Set oRptSource = Nothing
Set oCtlSource = Nothing
End Sub
Sub test()
ImporterEtat "c:\test.mde", "pannes non rendues"
End Sub
Private Function CreerControle(strNomEtat As String, oCtlSource As Object)
On Error GoTo err:
Dim oCtlDest As Object
Set oCtlDest = CreateReportControl(strNomEtat, oCtlSource.ControlType, oCtlSource.Section)
DupliqueProprietes oCtlSource, oCtlDest
err:
End Function
Private Function DupliqueProprietes(ObjetSource As Object, ObjetDest As Object)
On Error GoTo err
Dim Prp As Object
For Each Prp In ObjetSource.Properties
CloneProprietes ObjetDest, Prp
Next Prp
err:
End Function
Private Function CloneProprietes(ObjetDest As Object, PrpSource As Object)
On Error GoTo err
ObjetDest.Properties(PrpSource.Name).Value = PrpSource.Value
err:
End Function |
Partager