Input Password box in the Form. (1 Viewer)

smtazulislam

Member
Local time
Today, 12:49
Joined
Mar 27, 2020
Messages
806
Any help will appreciate.
In a FORM, I want to input box for insert USER password which password he enter to access database. If this password is correct then he can allow to edit this form.
Can possible ?

I dont like to Fixed Password in the VBA.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 09:49
Joined
Feb 19, 2013
Messages
16,553
perfectly possible and plenty of examples on this and other forums, but you will need to use vba.

however your request is not very clear - but sounds like you need something like this in the form open or current events or perhaps the click event of a button

me.allowedits=inputbox("Enter password to edit")="password"
 

smtazulislam

Member
Local time
Today, 12:49
Joined
Mar 27, 2020
Messages
806
me.allowedits=inputbox("Enter password to edit")="password"
Thank you so much for your reply.

eg. A database have user name and password to access database.
His userName = "Member" And Password is : "a123"

I want to do when he try to edit the FORM then inputbox to enter password which password (a123) user enter to access database.
Code:
Me.AllowEdit=InputBox("Enter password to edit")="password"
So I want to do something here: " ="Password" "
If I user Dlookup Replace FIXED PASSWORD place like : DLookup("Password", "tblUsers", "Password = '" & (How I call the text) & "'")
 

CJ_London

Super Moderator
Staff member
Local time
Today, 09:49
Joined
Feb 19, 2013
Messages
16,553
in that case

Code:
dim pword as string

pword=InputBox("Enter password to edit")
me.allowedits= DCount("Password", "tblUsers", "Password = '" & pword & "'")

but this just means a user could enter enter any valid password

So you need to have the username as well

DCount("Password", "tblUsers", "Password = '" & pword & "' AND member='" & gmember & "'")

gmember needs to be a global variable or tempvar which is populated when the user logs in. This example assumes you are storing the name, not a numeric ID

And if you are doing that, it might be relevant to store the user rights (to edit for example) as a global variable or tempvar so the question does not need to be asked, you would simply have in the form current or open events something like

me.allowedits=gUserCanEdit

where gUserCanEdit is a boolean
 

smtazulislam

Member
Local time
Today, 12:49
Joined
Mar 27, 2020
Messages
806
Code:
dim pword as string
pword=InputBox("Enter password to edit")
me.allowedits= DCount("Password", "tblUsers", "Password = '" & pword & "'")

but this just means a user could enter enter any valid password
So you need to have the username as well

DCount("Password", "tblUsers", "Password = '" & pword & "' AND member='" & gmember & "'")
thank you so much for your reply. sorry for late reply.
I use TempVar. It's worked. But, When I try to open the form then first time input box showed. If password is correct then open. if password is wrong then coming error message"94". How can I resolve this issue.

My code put in the Currect_Event.
I would like when I try to edit then input box display. Can Possible it.
Or I should use a button.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 09:49
Joined
Feb 19, 2013
Messages
16,553
no idea what error message 94 is, please provide the description. Also all the code associated with this - identify the line that fails

as to whether to use a button or not - all depends on how you want it to work. I suspect users will get very fed up with having to constantly enter a password. As I suggested before, set a tempvar when user first logs in
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:49
Joined
May 7, 2009
Messages
19,169
move your code to Dirty Event of the form

Private Sub Form_Dirty(Cancel As Integer)
pword=InputBox("Enter password to edit")
Cancel=(DCount("Password", "tblUsers", "Password = '" & pword & "'") = 0)
End Sub
 

smtazulislam

Member
Local time
Today, 12:49
Joined
Mar 27, 2020
Messages
806
move your code to Dirty Event of the form

Private Sub Form_Dirty(Cancel As Integer)
pword=InputBox("Enter password to edit")
Cancel=(DCount("Password", "tblUsers", "Password = '" & pword & "'") = 0)
End Sub
Thank so much for your reply.
I try it :
Code:
Private Sub Form_Dirty(Cancel As Integer)
Dim pword As String
pword = InputBox("Enter password to edit")
Me.AllowEdits = DCount("1", "Users", "[UserIDD]='" & txtUser & "' AND [Password]='" & pword & "'")
'Or also try 
Me.AllowEdits = DCount("1", "Users", "[UserIDD]='" & txtUser & "' AND [Password]='" & pword & "'" = 1)
Cancel = DCount("1", "Users", "[UserIDD]='" & txtUser & "' AND [Password]='" & pword & "'" = 0)

End Sub
But now problem is any password accepted. Even try to use Dlookup function. any mistake here ?

EDIT/
If I put this code in the Current event then worked, But If I enter the wrong password then came a error message "94"
 
Last edited:

smtazulislam

Member
Local time
Today, 12:49
Joined
Mar 27, 2020
Messages
806
I suggested before, set a tempvar when user first logs in
Thank you so much,
I do it TempVar in the first LOGON form. and my User name is display in the form. which form I try to edit.
But problem is when I enter any wrong Password then came error message.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:49
Joined
May 7, 2009
Messages
19,169
Private Sub Form_Dirty(Cancel As Integer)
Dim pword As String
pword = InputBox("Enter password to edit")
Cancel = (DCount("1", "Users", "[UserIDD]='" & txtUser & "' AND [Password]='" & pword & "'") = 0)
End Sub
 

smtazulislam

Member
Local time
Today, 12:49
Joined
Mar 27, 2020
Messages
806
Private Sub Form_Dirty(Cancel As Integer)
Dim pword As String
pword = InputBox("Enter password to edit")
Cancel = (DCount("1", "Users", "[UserIDD]='" & txtUser & "' AND [Password]='" & pword & "'") = 0)
End Sub
Oh! I have mistake two line I added.
thank you so much and It's really appreciated.
 

smtazulislam

Member
Local time
Today, 12:49
Joined
Mar 27, 2020
Messages
806
Private Sub Form_Dirty(Cancel As Integer)
Dim pword As String
pword = InputBox("Enter password to edit")
Cancel = (DCount("1", "Users", "[UserIDD]='" & txtUser & "' AND [Password]='" & pword & "'") = 0)
End Sub
Hello arnelgp,
If I would like to INPUTBOX replace a normal FORM. How can I do it ?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:49
Joined
May 7, 2009
Messages
19,169
If I would like to INPUTBOX replace a normal FORM. How can I do it ?
you will need to save the Value of the textbox on the form to some Public/Global variable
or to Tempvars collection.

then your code will change to:

Cancel = (DCount("1", "Users", "[UserIDD]='" & txtUser & "' AND [Password]='" & Tempvars!tvarPWD.Value & "'") = 0)
 

smtazulislam

Member
Local time
Today, 12:49
Joined
Mar 27, 2020
Messages
806
This is my FORM
 

Attachments

  • Capture.PNG
    Capture.PNG
    39.2 KB · Views: 422

smtazulislam

Member
Local time
Today, 12:49
Joined
Mar 27, 2020
Messages
806
Have any suggest to required password if user try to edit form. And without using the input box, I would like Post message #16 attached form use.
 

Users who are viewing this thread

Top Bottom