Ce code fonction sous access2016 pas sous access 365, même en déclarant ptrsafe devant les déclarations de fonction

si quelqu'un sait m'aider d'avance merci

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
Option Compare Database
Option Explicit
 
Private Const SM_CMONITORS As Long = 80&
Private Const SWP_NOSIZE As Long = &H1
Private Const SWP_NOACTIVATE As Long = &H10
Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
 
Private Type tagMONITORINFO
   cbSize As Long
   rcMonitor As RECT
   rcWork As RECT
   dwFlags As Long
End Type
Private Type MonitorData
    MonitorForm As Access.Form
    MonitorNumber As Long
End Type
 
Private Type MonitorData2
    MonitorReport As Access.Report
    MonitorNumber As Long
End Type
 
 
Private Declare ptrsafe Function GetMonitorInfo Lib "USER32" Alias "GetMonitorInfoA" (ByVal hMonitor As Long, ByRef tMonInfo As tagMONITORINFO) As Long
Private Declare ptrsafe Function GetSystemMetrics Lib "USER32" (ByVal nIndex As Long) As Long
Private Declare ptrsafe Function EnumDisplayMonitors Lib "USER32" (ByVal Hdc As Long, ByRef lprcClip As Any, ByVal lpfnEnum As Long, dwData As MonitorData) As Long
Private Declare ptrsafe Function SetWindowPos Lib "USER32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare ptrsafe Function GetWindowRect Lib "USER32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare ptrsafe Function EnumDisplayMonitorsCount Lib "USER32" Alias "EnumDisplayMonitors" (ByVal Hdc As Long, ByRef lprcClip As Any, ByVal lpfnEnum As Long, dwData As Long) As Long
Public aEcran(1 To 3) As RECT
 
'--------------------------------------------------------------
' Positionez un formulaire sur un moniteur spécifique
'--------------------------------------------------------------
' pForm : Formulaire à positionner
' pNumMoniteur : Numéro du moniteur
'--------------------------------------------------------------
Public Sub PosFormOnMonitor(pForm As Access.Form, Optional pNumMonitor As Long = 1)
    Dim ldata As MonitorData ' Données personnalisées pour énumération
    If GetSystemMetrics(SM_CMONITORS) > pNumMonitor Then Exit Sub
    Set ldata.MonitorForm = pForm
    ldata.MonitorNumber = pNumMonitor
    EnumDisplayMonitors ByVal 0&, ByVal 0&, AddressOf MonitorEnumProc, ldata
End Sub
 
Public Sub PosReportOnMonitor(pReport As Access.Report, Optional pNumMonitor As Long = 1)
    Dim ldata As MonitorData ' Données personnalisées pour énumération
    If GetSystemMetrics(SM_CMONITORS) > pNumMonitor Then Exit Sub
    Set ldata.MonitorForm = pReport
    ldata.MonitorNumber = pNumMonitor
    EnumDisplayMonitors ByVal 0&, ByVal 0&, AddressOf MonitorEnumProc, ldata
End Sub
 
' Enumération des moniteurs
Private Function MonitorEnumProc(ByVal hMonitor As Long, ByVal hdcMonitor As Long, lprcMonitor As RECT, dwData As MonitorData) As Long
Dim lInfo As tagMONITORINFO
Dim lFormRect As RECT
dwData.MonitorNumber = dwData.MonitorNumber
    ' Initialise la structure
    lInfo.cbSize = Len(lInfo)
    ' Info du moniteur
    GetMonitorInfo hMonitor, lInfo
    ' Taille formulaire
    GetWindowRect dwData.MonitorForm.hWnd, lFormRect
 
If dwData.MonitorNumber = 1 Then
 
    ' Positionne le formulaire sur le 1er moniteur
    SetWindowPos dwData.MonitorForm.hWnd, 0, _
                      ((lInfo.rcWork.Right - lInfo.rcWork.Left + 1) - (lFormRect.Right - lFormRect.Left + 1)) / 2, _
                      ((lInfo.rcWork.Bottom - (lInfo.rcWork.Top + 17) + 1) - (lFormRect.Bottom - lFormRect.Top + 1)) / 2, _
                       0, 0, SWP_NOSIZE
ElseIf dwData.MonitorNumber = 2 Then
 
    ' Positionne le formulaire sur le 2nd moniteur
   SetWindowPos dwData.MonitorForm.hWnd, 0, _
                      aEcran(1).Right + ((aEcran(2).Right - aEcran(2).Left + 1) - (lFormRect.Right - lFormRect.Left + 1)) / 2, _
                      ((aEcran(2).Bottom - (aEcran(2).Top + 17) + 1) - (lFormRect.Bottom - lFormRect.Top + 1)) / 2, _
                       0, 0, SWP_NOSIZE
ElseIf dwData.MonitorNumber = 3 Then
    ' Positionne le formulaire sur le 3nd moniteur
   SetWindowPos dwData.MonitorForm.hWnd, 0, _
                      aEcran(1).Right + aEcran(2).Right + ((aEcran(3).Right - aEcran(3).Left + 1) - (lFormRect.Right - lFormRect.Left + 1)) / 2, _
                      ((aEcran(3).Bottom - (aEcran(3).Top + 17) + 1) - (lFormRect.Bottom - lFormRect.Top + 1)) / 2, _
                       0, 0, SWP_NOSIZE
 
End If
    ' Stoppe l'énumération
    MonitorEnumProc = 0
End Function
 
Public Function CountMonitor() As Long
   Dim lCount As Long
   EnumDisplayMonitorsCount ByVal 0&, ByVal 0&, AddressOf MonitorEnumProcCount, lCount
   CountMonitor = lCount
End Function
 
Private Function MonitorEnumProcCount(ByVal hMonitor As Long, ByVal hdcMonitor As Long, lprcMonitor As RECT, dwData As Long) As Long
   dwData = dwData + 1
   aEcran(CInt(dwData)).Bottom = Abs(lprcMonitor.Bottom)
   aEcran(CInt(dwData)).Left = Abs(lprcMonitor.Left)
   aEcran(CInt(dwData)).Top = Abs(lprcMonitor.Top)
   aEcran(CInt(dwData)).Right = Abs(lprcMonitor.Right)
   'Debug.Print "ecran N°" & dwData; "|hauteur :=>" & aEcran(CInt(dwData)).Bottom & "|gauche :=>" & aEcran(CInt(dwData)).Left & "|haut:=> " & aEcran(CInt(dwData)).Top & "|Droite:=>"; aEcran(CInt(dwData)).Right
   MonitorEnumProcCount = 1
End Function