[FONT=Arial][FONT=Arial]Option Private Module[/FONT]
[FONT=Arial]Option Compare Database[/FONT]
[FONT=Arial]Option Explicit[/FONT]
[FONT=Arial]'Modified from Access 2010 Programmer's Reference.[/FONT]
[FONT=Arial]Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000[/FONT]
[FONT=Arial]#If Win64 = 1 And VBA7 = 1 Then[/FONT]
[FONT=Arial] Declare PtrSafe Function FormatMessage Lib "kernel32" Alias "FormatMessageW" _[/FONT]
[FONT=Arial] (ByVal dwFlags As Long, lpSource As Long, ByVal dwMessageId As Long, _[/FONT]
[FONT=Arial] ByVal dwLanguageId As Long, ByVal lpBuffer As LongPtr, ByVal nSize As Long, Arguments As Any) As Long[/FONT]
[FONT=Arial]#ElseIf VBA6 = 1 Then[/FONT]
[FONT=Arial] Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageW" _[/FONT]
[FONT=Arial] (ByVal dwFlags As Long, lpSource As Long, ByVal dwMessageId As Long, _[/FONT]
[FONT=Arial] ByVal dwLanguageId As Long, ByVal lpBuffer As Long, ByVal nSize As Long, Arguments As Any) As Long[/FONT]
[FONT=Arial]#End If[/FONT]
[FONT=Arial]Public Function GetAPIErrorMessage(lngError As Long) As String[/FONT]
[FONT=Arial] Dim strMessage As String[/FONT]
[FONT=Arial] Dim lngReturn As Long[/FONT]
[FONT=Arial] Dim nSize As Long[/FONT]
[FONT=Arial] strMessage = Space(256)[/FONT]
[FONT=Arial] nSize = Len(strMessage)[/FONT]
[FONT=Arial] lngReturn = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, _[/FONT]
[FONT=Arial] lngError, 0, StrPtr(strMessage), nSize, 0)[/FONT]
[FONT=Arial] If lngReturn > 0 Then[/FONT]
[FONT=Arial] GetAPIErrorMessage = Replace(Left(strMessage, lngReturn), vbCrLf, "")[/FONT]
[FONT=Arial] Else[/FONT]
[FONT=Arial] GetAPIErrorMessage = "Error not found."[/FONT]
[FONT=Arial] End If[/FONT]
[FONT=Arial]End Function[/FONT]
[FONT=Arial]Public Function LoWord(dw As Long) As Integer[/FONT]
[FONT=Arial] 'Retrieves the low-order word from the given 32-bit value. Provided by Allen Browne.[/FONT]
[FONT=Arial] If dw And &H8000& Then[/FONT]
[FONT=Arial] LoWord = dw Or &HFFFF0000[/FONT]
[FONT=Arial] Else[/FONT]
[FONT=Arial] LoWord = dw And &HFFFF&[/FONT]
[FONT=Arial] End If[/FONT]
[FONT=Arial]End Function[/FONT]
[FONT=Arial]Public Function HiWord(dw As Long) As Integer[/FONT]
[FONT=Arial] 'Retrieves the high-order word from the given 32-bit value. Provided by Allen Browne.[/FONT]
[FONT=Arial] HiWord = (dw And &HFFFF0000) \ &H10000[/FONT]
[FONT=Arial]End Function[/FONT]
[/FONT]