We've been using the password masked inputbox script found on this message board written Daniel Klann for a while, it is fabulous!
http://www.mrexcel.com/forum/showthread.php?t=406176&highlight=klann
http://www.danielklann.com/excel/hiding_text_in_a_vba_inputbox.htm (no longer active)
However the * mask does not work in MSAccess 2010 64 bit. It is fine in MSAccess 2010 32 bit.
HERE IS A QUICK OVERVIEW:
We've been using the script in an MSAccess 97 database for a long time without any issues. Now they're upgrading to Microsoft Office 2010 64 bit version. To make it work, we a few minor coding adjustments:
1.) "Microsoft DOA 3.6 object Library" was missing on 64 bit machine, change reference to "Microsoft Office 12.0 Access Database Engine Object Library”
2.) Add "PtrSafe" to declare statements - Private Declare PtrSafe ...
3.) Changed variable "lpfn" data type to LongPtr instead of Long
After making the above coding adjustments, the msgbox works except one odd behavior. When the user enters the password in the msgbox, it is not masked with asterisk ***. The password displays as normal readable text.
The * mask works correctly on a machine with MSAccess 2010 32 bit. The * mask just doesn't work in the MSAccess 2010 64 bit. We're on Windows 7.
Not sure what I'm doing wrong or missing. If anyone has any suggestions, it is most appreciated.
HERE IS THE CODE SNIPPET:
'////////////////////////////////////////////////////////////////////
'Password masked inputbox
'Allows you to hide characters entered in a VBA Inputbox.
'
'Code written by Daniel Klann
'March 2003
'
' http://www.danielklann.com/excel/hiding_text_in_a_vba_inputbox.htm
'
' MOD 2012-01-10 - modified to work in MS Access 64 bit
' PtrSafe and LongPtr, reference - Microsoft Office 12.0 Access Database Engine Object Library
'////////////////////////////////////////////////////////////////////
'API functions to be used
Private Declare PtrSafe Function CallNextHookEx Lib "User32" (ByVal hHook As Long, _
ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare PtrSafe Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
Private Declare PtrSafe Function SetWindowsHookEx Lib "User32" Alias "SetWindowsHookExA" _
(ByVal idHook As Long, ByVal lpfn As LongPtr, ByVal hmod As Long, _
ByVal dwThreadId As Long) As Long
Private Declare PtrSafe Function UnhookWindowsHookEx Lib "User32" (ByVal hHook As Long) As Long
Private Declare PtrSafe Function SendDlgItemMessage Lib "User32" Alias "SendDlgItemMessageA" _
(ByVal hDlg As Long, ByVal nIDDlgItem As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare PtrSafe Function GetClassName Lib "User32" Alias "GetClassNameA" (ByVal hwnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Private Declare PtrSafe Function GetCurrentThreadId Lib "kernel32" () As Long
Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Declare PtrSafe Function apiGetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
'Constants to be used in our API functions
Private Const EM_SETPASSWORDCHAR = &HCC
Private Const WH_CBT = 5
Private Const HCBT_ACTIVATE = 5
Private Const HC_ACTION = 0
Private hHook As Long
Public Function NewProc(ByVal lngCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim RetVal
Dim strClassName As String, lngBuffer As Long
If lngCode < HC_ACTION Then
NewProc = CallNextHookEx(hHook, lngCode, wParam, lParam)
Exit Function
End If
strClassName = String$(256, " ")
lngBuffer = 255
If lngCode = HCBT_ACTIVATE Then 'A window has been activated
RetVal = GetClassName(wParam, strClassName, lngBuffer)
If Left$(strClassName, RetVal) = "#32770" Then 'Class name of the Inputbox
'This changes the edit control so that it display the password character *.
'You can change the Asc("*") as you please.
SendDlgItemMessage wParam, &H1324, EM_SETPASSWORDCHAR, Asc("*"), &H0
End If
End If
'This line will ensure that any other hooks that may be in place are
'called correctly.
CallNextHookEx hHook, lngCode, wParam, lParam
End Function
Public Function InputBoxDK(Prompt, Optional title, Optional Default, Optional XPos, _
Optional YPos, Optional HelpFile, Optional Context) As String
Dim lngModHwnd As Long, lngThreadID As Long
lngThreadID = GetCurrentThreadId
lngModHwnd = GetModuleHandle(vbNullString)
hHook = SetWindowsHookEx(WH_CBT, AddressOf NewProc, lngModHwnd, lngThreadID)
InputBoxDK = InputBox(Prompt, title, Default, XPos, YPos, HelpFile, Context)
UnhookWindowsHookEx hHook
End Function
http://www.mrexcel.com/forum/showthread.php?t=406176&highlight=klann
http://www.danielklann.com/excel/hiding_text_in_a_vba_inputbox.htm (no longer active)
However the * mask does not work in MSAccess 2010 64 bit. It is fine in MSAccess 2010 32 bit.
HERE IS A QUICK OVERVIEW:
We've been using the script in an MSAccess 97 database for a long time without any issues. Now they're upgrading to Microsoft Office 2010 64 bit version. To make it work, we a few minor coding adjustments:
1.) "Microsoft DOA 3.6 object Library" was missing on 64 bit machine, change reference to "Microsoft Office 12.0 Access Database Engine Object Library”
2.) Add "PtrSafe" to declare statements - Private Declare PtrSafe ...
3.) Changed variable "lpfn" data type to LongPtr instead of Long
After making the above coding adjustments, the msgbox works except one odd behavior. When the user enters the password in the msgbox, it is not masked with asterisk ***. The password displays as normal readable text.
The * mask works correctly on a machine with MSAccess 2010 32 bit. The * mask just doesn't work in the MSAccess 2010 64 bit. We're on Windows 7.
Not sure what I'm doing wrong or missing. If anyone has any suggestions, it is most appreciated.
HERE IS THE CODE SNIPPET:
'////////////////////////////////////////////////////////////////////
'Password masked inputbox
'Allows you to hide characters entered in a VBA Inputbox.
'
'Code written by Daniel Klann
'March 2003
'
' http://www.danielklann.com/excel/hiding_text_in_a_vba_inputbox.htm
'
' MOD 2012-01-10 - modified to work in MS Access 64 bit
' PtrSafe and LongPtr, reference - Microsoft Office 12.0 Access Database Engine Object Library
'////////////////////////////////////////////////////////////////////
'API functions to be used
Private Declare PtrSafe Function CallNextHookEx Lib "User32" (ByVal hHook As Long, _
ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare PtrSafe Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
Private Declare PtrSafe Function SetWindowsHookEx Lib "User32" Alias "SetWindowsHookExA" _
(ByVal idHook As Long, ByVal lpfn As LongPtr, ByVal hmod As Long, _
ByVal dwThreadId As Long) As Long
Private Declare PtrSafe Function UnhookWindowsHookEx Lib "User32" (ByVal hHook As Long) As Long
Private Declare PtrSafe Function SendDlgItemMessage Lib "User32" Alias "SendDlgItemMessageA" _
(ByVal hDlg As Long, ByVal nIDDlgItem As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare PtrSafe Function GetClassName Lib "User32" Alias "GetClassNameA" (ByVal hwnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Private Declare PtrSafe Function GetCurrentThreadId Lib "kernel32" () As Long
Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Declare PtrSafe Function apiGetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
'Constants to be used in our API functions
Private Const EM_SETPASSWORDCHAR = &HCC
Private Const WH_CBT = 5
Private Const HCBT_ACTIVATE = 5
Private Const HC_ACTION = 0
Private hHook As Long
Public Function NewProc(ByVal lngCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim RetVal
Dim strClassName As String, lngBuffer As Long
If lngCode < HC_ACTION Then
NewProc = CallNextHookEx(hHook, lngCode, wParam, lParam)
Exit Function
End If
strClassName = String$(256, " ")
lngBuffer = 255
If lngCode = HCBT_ACTIVATE Then 'A window has been activated
RetVal = GetClassName(wParam, strClassName, lngBuffer)
If Left$(strClassName, RetVal) = "#32770" Then 'Class name of the Inputbox
'This changes the edit control so that it display the password character *.
'You can change the Asc("*") as you please.
SendDlgItemMessage wParam, &H1324, EM_SETPASSWORDCHAR, Asc("*"), &H0
End If
End If
'This line will ensure that any other hooks that may be in place are
'called correctly.
CallNextHookEx hHook, lngCode, wParam, lParam
End Function
Public Function InputBoxDK(Prompt, Optional title, Optional Default, Optional XPos, _
Optional YPos, Optional HelpFile, Optional Context) As String
Dim lngModHwnd As Long, lngThreadID As Long
lngThreadID = GetCurrentThreadId
lngModHwnd = GetModuleHandle(vbNullString)
hHook = SetWindowsHookEx(WH_CBT, AddressOf NewProc, lngModHwnd, lngThreadID)
InputBoxDK = InputBox(Prompt, title, Default, XPos, YPos, HelpFile, Context)
UnhookWindowsHookEx hHook
End Function