Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Advanced 4    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
idea re password to open form
Sarah Bliss 
     
2 years ago
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"

Have a nice day,
Sarah
Richard Rost  @Reply  
          
2 years ago
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)
Richard Rost  @Reply  
          
2 years ago
Richard Rost  @Reply  
          
2 years ago
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

        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 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


Adjust to do what you need it to
Richard Rost  @Reply  
          
2 years ago
You not gonna slap a Detail tag around that giant piece of code, sir?
Adam Schwanz  @Reply  
           
2 years ago

Adam Schwanz  @Reply  
           
2 years ago
I thought I had another line or two before it called for the Detail tag LOL
Richard Rost  @Reply  
          
2 years ago
More than a screenful... details that sucker.
Sarah Bliss OP  @Reply  
     
2 years ago
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. &#128512;
Richard Rost  @Reply  
          
2 years ago
If that's the case, ignore the monster block of code that Adam posted, and just stick with your simple popup form.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Advanced 4.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 6/13/2026 4:47:48 PM. PLT: 1s