Password protecting a single form (1 Viewer)

whoisit

Registered User.
Local time
Today, 03:40
Joined
Oct 27, 2004
Messages
28
i have placed a password on a number of forms. How it works is i have a sort of main menu with a number of buttons on them to open a number of forms. When i click on the button it asks me for a password then opens the form

Here is the code for my form "frmEditMemberDetails". On the form properties this code is placed in the "On Open" property

Private Sub Form_Click()
Private Sub Form_Open(Cancel As Integer)
Dim x As String
x = "password"
Dim y As String
y = InputBox("Enter Password for form")
If x <> y Then
MsgBox ("Invalid password")
DoCmd.CancelEvent

End If
End Sub



But unfortunately this does not display the password in the form of *
Can anyone help me to put a mask on the password entered.
I am a beginner in VB
THANK YOU
 

ghudson

Registered User.
Local time
Yesterday, 22:40
Joined
Jun 8, 2002
Messages
6,195
You can not format an input box. You will have to use a text box with the PASSWORD format for the input mask. I suggest adding a text box on the main for to do this and make the password text box visible when needed. Or you could create a new 'password' form and make it appear when needed to verify the password. The latter will take more effort.
 

Mile-O

Back once again...
Local time
Today, 03:40
Joined
Dec 10, 2002
Messages
11,316
You can't password "*" an InputBox.

The only solution is create a small modal/popup form with a textbox. The textbox's InputMask property should be set to Password.

There have been examples in the past if you care to search.
 

charityg

Registered User.
Local time
Today, 03:40
Joined
Apr 17, 2001
Messages
634
I just wanted to post that this type of functionality IS possible with an input box, though hardly worth the coding efforts when you can just create a security form.

==================
Some Form Button code
==================
Private Sub Command0_Click()
Dim pResponse As String
Dim lSalesPersonID As Long
Dim lEditHwnd As Long
Dim lTemp As Long
Dim sPwd As String
gMsgTitle = "[Security Check] - Modifying Credit Limit"
gMsgType = vbOKOnly + vbInformation
gMsgText = "Enter database password for Fred"
Beep

lTemp = SetTimer(Me.hwnd, NV_INPUTBOX, 1, AddressOf TimerProc)
sPwd = InputBox(gMsgText, gMsgTitle)
MsgBox "the password you entered was: " & sPwd
End Sub
===== End Some Form Button Code ========






=======================
New Module
=======================
Option Compare Database
Option Explicit

' --- Global Constants (Messages) ------------------------------------
Global gMsgText As String 'Text in MsgBox() and InputBox() functions
Global gMsgType As Integer 'Type in MsgBox() and InputBox() functions
Global gMsgTitle As String 'Title for MsgBox() and InputBox() function
Global gStatusText As String 'Status bar text used in Application.Echo method

' API set A:
' Used by the callback process (TimerProc) to hook into
' the InputBox window
' Ref: http://pub13.ezboard.com/fvisualbasicexplorervbtips.showMessage?topicID=314.topic

Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

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

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


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

Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
' Constants for API set A
Const EM_SETPASSWORDCHAR = &HCC
Public Const NV_INPUTBOX As Long = &H5000&

Public Function TimerProc(ByVal lHwnd&, ByVal uMsg&, _
ByVal lIDEvent&, ByVal lDWTime&) As Long
Dim lTemp As Long
' This function allows for a mask character on an inputbox
' ' Usage (Replace anything between [] with valid names from your project):
' From a form or module:
' 1. Declare a Long variable
' 2. Call the timer function: [variable] = SetTimer([form].Hwnd, NV_INPUTBOX, [elapsed time], AddressOf [function name])
' 2b. Example usage from a form: lTemp = SetTimer(Me.Hwnd, NV_INPUTBOX, 1, AddressOf TimerProc)
' 3. Create your InputBox as usual

Dim lEditHwnd As Long

' Find a handle to the InputBox window, then to the textbox
' the user types in (Known as "Edit")
' ' **This part is VERY important, here is how the FindWindowEx call should look:
' **Only change the parameters that are enclosed in [ ] in the following example
lTemp = FindWindowEx(FindWindow("#32770", "[gMsgText]"), 0, "Edit", "")
lEditHwnd = FindWindowEx(FindWindow("#32770", gMsgTitle), 0, "Edit", "")

' Send the mask character to the target InputBox when the user types
' The mask character in this sample is the Asc("*") - the "*" can be changed
' to whatever you like.

Call SendMessage(lEditHwnd, EM_SETPASSWORDCHAR, Asc("#"), 0)
' Destroy the timer object when done (The user clicks OK or Cancel from the InputBox)
KillTimer lHwnd, lIDEvent

End Function

=======End Module===========================
 

Users who are viewing this thread

Top Bottom