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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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


Did you find out about this? I have a 64 bit system and have also Issue with the code. I have 2013 access though :)
 
Upvote 0
The code are now:

Code:
Public sPwd As String
Public gMsgTitle As String
Public gMsgType As String
Public gMsgText As String
Public gStatusText As String

"FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Private Declare PtrSafe Function FindWindowEx Lib "user32" Alias _
"FindWindowExA" (ByVal hWnd1 As LongPtr, ByVal hWnd2 As LongPtr, _
ByVal lpsz1 As String, ByVal lpsz2 As String) As LongPtr

Public Declare PtrSafe Function SetTimer& Lib "user32" _
(ByVal hwnd&, ByVal nIDEvent&, ByVal uElapse&, ByVal _
lpTimerFunc&)

Public Declare PtrSafe Function KillTimer& Lib "user32" _
(ByVal hwnd&, ByVal nIDEvent&)

Private Declare PtrSafe Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As LongPtr, _
ByVal wParam As LongPtr, lParam As Any) As LongPtr

Const EM_SETPASSWORDCHAR = &HCC
Public Const NV_INPUTBOX As Long = &H5000&

And Function:

Code:
Public Function TimerProc(ByVal lHwnd&, ByVal uMsg&, _
ByVal lIDEvent&, ByVal lDWTime&) As LongPtr

Dim lTemp As Long
Dim lEditHwnd As Long
lTemp = FindWindowEx(FindWindow("#32770", "gMsgText"), 0, "Edit", "")
lEditHwnd = FindWindowEx(FindWindow("#32770", "gMsgTitle"), 0, "Edit", "")

Call SendMessage(lEditHwnd, EM_SETPASSWORDCHAR, Asc("*"), 0)

KillTimer lHwnd, lIDEvent
End Function

Input box:

Code:
Private Sub OpnAdm_Click()

gMsgTitle = "Begrenset Omrde"
gMsgType = vbOKOnly + vbInformation
gMsgText = "Tast inn passord"
  

lTemp = SetTimer(Me.hwnd, NV_INPUTBOX, 1, AddressOf TimerProc)
sPwd = InputBox(gMsgText, gMsgTitle)


If strPasswd = "" Or strPasswd = Empty Then
Exit Sub
End If

If strPasswd = "yslg53481" Then
DoCmd.OpenForm "frmBatchReg"
Else
MsgBox "Beklager, du har ikke tilgang til denne delen av programmet", vbOKOnly, "Sikkerhetssjekk"
Exit Sub
End If


End Sub

Missing anything? The error I get is type missmatch on AddressOf TimerProc. But I know its also needs converting to 64 bit. Don't know how tough.
 
Upvote 0
Posted this on other forums; Just for information (got some angry moderators breathing down my neck;):
I have posted this issue on several forums, simply because I don't think it's an easy fix, and most likley It's just a few people who can solve this ( Daniel Kann and 10 others mabe Xp ). Where they are is hard to know, so I have multiplyed the chances of finding them by going wide on the internett. Do not worry on dobbeltsolving this problem, the minuite we find a solution its out on every forum. I don not want others to use as much time on this as I have. In fact I hope to mabe make a youtube video :) But first the problem needs solving ;) So thx anyway for reading, I am quite on my deapth here now, so ain't getting further here without anyone with a little more experience :)

Regards
-Kv
 
Upvote 0
Hi Kv

Unfortunately I do not have a 64 bit version of Office - even the Office 365 version I have on my home desktop is 32 bit and I don't even remember being asked which version I wanted so I guess MS still give 32 bit as the default. Anyway, is it possible for you to use a form instead with the Input Mask property set to Password?

Cheers
DK
 
Upvote 0

Forum statistics

Threads
1,215,756
Messages
6,126,692
Members
449,331
Latest member
smckenzie2016

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