Hi Richard. You say it is complicated to put asterisks instead of the password. I thought you might be interested in how I did it (before I got anyway near these lessons of yours):
I used an unbound form (PasswordF) instead of an input box with only one, unbound control - PasswordBox with a label "Inserire password" (this means "Insert password", I'm doing this for Italians). I used an input mask (passsword) for the password and Code on the PasswordBox AfterUpdate event:
Private Sub PasswordBox_AfterUpdate()
If Forms!PasswordF!PasswordBox <> "gelato" Then MsgBox "Password errato!", vbCritical DoCmd.Close Else DoCmd.Close DoCmd.OpenForm "MenuManutenzioneF" End If
End Sub
The password is required to open the "MenuManutenzioneF"
Oh yes... Using the password input mask is easy. I think I cover that in the beginner lessons. It's not easy (or even possible) to do with an inputbox... Which I think is what I'm talking about here (it's been so long. Lol)
Adam has found some code that allows you to do it by going out and calling Windows DLLs. I've seen something similar before. I should have said "it's not possible to do it with just Access's tools and code. If you're going out to the Windows DLLs, then sure... almost anything's possible."
Adam Schwanz
@Reply 2 years ago
Sharing incase anyone is interested.
Make a module with this
DetailsOption Compare Database
Option Explicit
Private Declare PtrSafe Function CallNextHookEx Lib "user32" (ByVal hHook As LongPtr, ByVal ncode As Long, ByVal wParam As LongPtr, lParam As Any) As Long
Private Declare PtrSafe Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As LongPtr
Private Declare PtrSafe Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As LongPtr, ByVal hmod As LongPtr, ByVal dwThreadId As Long) As LongPtr
Private Declare PtrSafe Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As LongPtr) As Long
Private Declare PtrSafe Function SendDlgItemMessage Lib "user32" Alias "SendDlgItemMessageA" (ByVal hDlg As LongPtr, ByVal nIDDlgItem As Long, ByVal wMsg As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As LongPtr
Private Declare PtrSafe Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As LongPtr, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare PtrSafe Function GetCurrentThreadId Lib "kernel32" () 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 LongPtr
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
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 As String, Optional Title As String, _
Optional Default As String, _
Optional Xpos As LongPtr, _
Optional Ypos As LongPtr, _
Optional Helpfile As String, _
Optional Context As LongPtr) As String
Dim lngModHwnd As LongPtr, lngThreadID As Long
'// Lets handle any Errors JIC! due to HookProc> App hang!
On Error GoTo ExitProperly
lngThreadID = GetCurrentThreadId
lngModHwnd = GetModuleHandle(vbNullString)
hHook = SetWindowsHookEx(WH_CBT, AddressOf NewProc, lngModHwnd, lngThreadID)
If Xpos Then
InputBoxDK = InputBox(Prompt, Title, Default, Xpos, Ypos, Helpfile, Context)
Else
InputBoxDK = InputBox(Prompt, Title, Default, , , Helpfile, Context)
End If
ExitProperly:
UnhookWindowsHookEx hHook
End Function
Sub TestDKInputBox()
Dim x
x = InputBoxDK("Type your password here.", "Password Required")
If x = "" Then End
If x <> "yourpassword" Then
MsgBox "You didn't enter a correct password."
End
End If
MsgBox "Welcome Creator!", vbExclamation
End Sub
Then call the code with
Private Sub Command0_Click()
Call TestDKInputBox
End Sub
Thank you, both. I'm afraid this last stuff is way over my head! I'm having to go slowly to make my head do what I tell it!
You'll have to forgive me, I'm old enough to be your granny but I'll get there. 😀
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.
This thread is now CLOSED. If you wish to comment, start a NEW discussion in
Access Advanced 4.