password masked msgbox on msaccess 64 bit

smiles

New Member
Joined
Dec 14, 2004
Messages
17
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
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Unfortunately Access 2010 64-buit version has lots of issues. I would avoid it if at all possible.
 
Upvote 0
I have not tried to convert 32 bit API calls to 64 bit compatibility since I do not support Access 2010 64-bit.

The simple solution is to switch to using a form. I have always used the built-in feature of a a text box to have a Password mask. This works in all versions of Access without any issues. No API calls calls since it is native.

I will do some research to see to if I can find a solution.

Let use know if you find an API solution. I would like to see gow it is done.
 
Upvote 0
Good suggestion. Hopefully there is an API solution, otherwise I'll definitely utilize your suggestion and switch to a form masked text box. Thanks again HiTechCoach!
 
Upvote 0
Hi,

I will have a look at converting this code when I get a chance - I don't have any 64 bit office installation at the moment but will get one set up and see if I can get the code to work. For sake of simplicity in solving your problem I would also use a userform (the code I originally wrote was more of an academic exercise anyway). I haven't looked at this code for quite a few years but I would guess that the problem is with either this:

Code:
If Left$(strClassName, RetVal) = "#32770" Then 'Class name of the Inputbox
or this

Code:
SendDlgItemMessage wParam, &H1324, EM_SETPASSWORDCHAR, Asc("*"), &H0

The values used in 32 bit Office (#32770 and &H1324) may possibly be different in 64 bit. It has been so long since I wrote this code that I can barely remember how I got these numbers (thinking that I used Spy++ that came with VB6 that I don't even have installed on my development machine any more!). However, I would be keen to see if I can brush up on the changes to the WinAPI re 64 bit Office.

Will reply if I come up with a solution.

Cheers
DK
 
Last edited:
Upvote 0
Turns out we won't have to worry about 64 bit after all, staying 32 bit. A millions thanks, I've learned some great techniques and troubleshooting ideas from everyone on this forum.
 
Upvote 0
Turns out we won't have to worry about 64 bit after all, staying 32 bit. A millions thanks, I've learned some great techniques and troubleshooting ideas from everyone on this forum.


You're welcome.

I still would recommend that you switch to using a form. Then your compatibility issues should go away forever.
 
Upvote 0
Thanks HiTechCoach, good idea, we're switching to the form solution to avoid any future issue, looks good.
 
Upvote 0

Forum statistics

Threads
1,215,149
Messages
6,123,311
Members
449,095
Latest member
Chestertim

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top