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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
| Option Explicit
' API Pour la gestion des touches du clavier:
Private Declare PtrSafe Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As LongPtr)
Private Declare PtrSafe Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Declare PtrSafe Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
' Constantes pour la gestion des touches du clavier:
Private Const VK_NUMLOCK = &H90
Private Const VK_CAPITAL = &H14
Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2
'------------------------------------------------------------------------------------------------
Private Sub SetKeyState(ByVal Key As Long, ByVal State As Boolean)
'------------------------------------------------------------------------------------------------
keybd_event Key, MapVirtualKey(Key, 0), KEYEVENTF_EXTENDEDKEY Or 0, 0
keybd_event Key, MapVirtualKey(Key, 0), KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0
If Key = 20 And State = False Then ' cas particulier pour VK_CAPITAL
keybd_event 16, 0, 0, 0
keybd_event 16, 0, 2, 0
End If
End Sub
'------------------------------------------------------------------------------------------------
Public Sub SetNumLock(Etat As Boolean)
'------------------------------------------------------------------------------------------------
' Etat = True : Active le clavier numérirque.
' Etat = False : Désactive le clavier numérique.
'------------------------------------------------------------------------------------------------
While GetKeyState(VK_NUMLOCK) = 1 + Etat
SetKeyState VK_NUMLOCK, Etat
DoEvents
Wend
End Sub
'------------------------------------------------------------------------------------------------
Public Sub SetCapital(Etat As Boolean)
'------------------------------------------------------------------------------------------------
' Etat = True : Active le mode majuscule.
' Etat = False : Désactive le mode majuscule.
'------------------------------------------------------------------------------------------------
While GetKeyState(VK_CAPITAL) = 1 + Etat
SetKeyState VK_CAPITAL, Etat
DoEvents
Wend
End Sub
'------------------------------------------------------------------------------------------------
'------------------------------------------------------------------------------------------------
Sub CodeTemplate()
'--------------------------------------------------------------
'Purpose :Inser an error trapping code into your sub or function
'Notes :place the caret between the "Function" or "Sub" line and the "End Function" line.
' :and click Makro > CodeTemplate()
' :Needs ZZ_frmTemplate to swap value to the clipboard
'Author :Larroque 06.06.2001
'--------------------------------------------------------------
On Error GoTo Err_CodeTemplate
Dim strMsg As String
Dim strText As String
Dim strName As String
Dim intStart As Integer, intStop As Integer
Dim strType As String
Application.Echo False
SetNumLock (False)
SendKeys "{Up 1}" 'place the Sub Name into clipboard
SendKeys "+{End}"
SendKeys "^{INSERT}", True
DoCmd.OpenForm "ZZ_frmTemplate" 'Pass it to the form control
Forms!ZZ_frmTemplate!txtFinal.SetFocus
SendKeys "+{INSERT}", True
SendKeys "{TAB}"
DoEvents 'and to the variable
strName = Forms!ZZ_frmTemplate!txtFinal.Value
DoCmd.Close
If InStr(strName, "Private Sub") Then 'seek the beginning of the sub Name
intStart = InStr(strName, "Private Sub") + 12
intStop = InStr(strName, "(") 'seek the end of the sub Name
strName = Mid$(strName, intStart, intStop - intStart) 'read the name
strType = "Sub"
ElseIf InStr(strName, "Public Sub") Then
intStart = InStr(strName, "Public Sub") + 11
intStop = InStr(strName, "(")
strName = Mid$(strName, intStart, intStop - intStart)
strType = "Sub"
ElseIf InStr(strName, "Sub") Then
intStart = InStr(strName, "Sub") + 4
intStop = InStr(strName, "(")
strName = Mid$(strName, intStart, intStop - intStart)
strType = "Sub"
ElseIf InStr(strName, "Function") Then
intStart = InStr(strName, "Function") + 9
intStop = InStr(strName, "(")
strName = Mid$(strName, intStart, intStop - intStart)
strType = "Function"
End If
strText = "'--------------------------------------------------------------" & vbCrLf
strText = strText & "'Purpose :" & vbCrLf
strText = strText & "'Notes :" & vbCrLf
strText = strText & "'Author : Larroque " & Format(Now, "dd/mm/yyyy") & vbCrLf
strText = strText & "'--------------------------------------------------------------" & vbCrLf
strText = strText & " On Error GoTo Err_" & strName & vbCrLf
strText = strText & " Dim strMsgErr As String" & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf
strText = strText & " Err_" & strName & "_End" & ":" & vbCrLf
strText = strText & " On Error GoTo 0 " & vbCrLf
strText = strText & " Exit " & strType & vbCrLf
strText = strText & " Err_" & strName & ":" & vbCrLf
strText = strText & " strMsgErr = ""Error Information..."" & vbCrLf & vbCrLf" & vbCrLf
strText = strText & " strMsgErr = strMsgErr & """ & strType & ": " & strName & """ & vbCrLf" & vbCrLf
strText = strText & " strMsgErr = strMsgErr & ""Description: "" & Err.Description & vbCrLf" & vbCrLf
strText = strText & " strMsgErr = strMsgErr & ""Error #: "" & Format$(Err.Number) & vbCrLf" & vbCrLf
strText = strText & " Call LogError(strMsgErr)" & vbCrLf
strText = strText & " MsgBox strMsgErr, vbInformation, """ & strName & """ " & vbCrLf
strText = strText & " Resume Err_" & strName & "_End" & vbCrLf
DoCmd.OpenForm "ZZ_frmTemplate"
Forms!ZZ_frmTemplate!txtFinal = strText
Forms!ZZ_frmTemplate!txtFinal.SetFocus
DoCmd.RunCommand acCmdCopy
'SendKeys "^{INSERT}", True
DoCmd.Close
SendKeys "{DOWN}"
SendKeys "+{INSERT}"
SendKeys "{UP 13}"
SendKeys "{TAB}"
Application.Echo True
Err_CodeTemplate_End:
On Error GoTo 0
Exit Sub
Err_CodeTemplate:
strMsg = "Error Information..." & vbCrLf & vbCrLf
strMsg = strMsg & "Sub: CodeTemplate" & vbCrLf
strMsg = strMsg & "Description: " & Err.Description & vbCrLf
strMsg = strMsg & "Error #: " & Format$(Err.Number) & vbCrLf
' Call LogError(strMsg)
MsgBox strMsg, vbInformation, "CodeTemplate"
Resume Err_CodeTemplate_End
End Sub |
Partager