Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Password protection to forms

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello all!
I am working with a few forms in which I would like to give password protection to a form. It's like FORMA ---> PASSWORD----> FORMB. Can password protection be given to this form? And if it is possible, Could you please let me know a way to do it? I have an idea of displaying a textbox and a submit buton(a password form in between ).Any suggestions would be appreciated.

Thanks!
 
if you don't want to use access security then this will fake non experienced users

put in the forms on load event

dim strpword as string
strpword = inputbox("Enter password")
if strpword = "Password here"
exit sub
else
docmd.close
end if
 
formpas:

If you are working on a network you can prevent unauthorized users from accessing the database by comparing the CurrentUser name to a list maintained in the database.

I create a table of allowed users with the key field being the known UserName (network logon). I then create a Main screen as the Startup Form and in the On_Load event use this code:

Private Sub Form_Load()
On Error GoTo Err_Form_Load

Dim dbTemp As Database
Dim rsTemp As Recordset
Dim strSQL As String

strSQL = "SELECT UserName FROM tblUsers WHERE UserName = '" & CurrentUser & "' ; "

Set dbTemp = CurrentDb
Set rsTemp = dbTemp.OpenRecordset(strSQL)

rsTemp.Close

Exit_Form_Load:
Exit Sub

Err_Form_Load:
MsgBox "You are not authorized to access this database", vbOKOnly, "WARNING"
Quit

Only thing you need to do after that is to train your users not to leave for lunch without signing off the network or locking the workstation.
Larry De Laruelle
larry1de@yahoo.com

 
For the "fake" password setup, can the input box for the password be set to show ***** instead of the password when it is entered?
 
You can set the input mask to "Password" and that will give you the **** that you are looking for.
 
How do I do this in the code posted by "braindead" a few post above? I dont have a form I just get the inputbox from his code.
 
Hi,
This is Trappinout. What method of vba/sql would best be used to take the user name and password from a logon form and validate them against a table in another access database. If a match is found a swithboard would be opened. The switchboard has a combobox currently showing results based on who logged in. The combobox uses a SQL statement looking for the userid and password from the form.

Thank you in advance.
 
Trap - here's something I did about 5 years ago. It takes a user name and password entered on a form, finds the match for BOTH in a user-table, and goes from there:
----------------------------------------
Private Sub StartBTN_Click()
Dim rst As Recordset
Set rst = Currentdb.OpenRecordset("Users")

rst.Index = "PrimaryKey"
rst.Seek "=", Me.txtUserName

If rst.NoMatch Then
msgbox ("Sorry, that user name was not found. Please check your entry and try again!")
Exit Sub
End If

If txtPassword = rst![Password] Then
UserName = rst![UserName]
UserAccess = rst![Access]
With DoCmd
.OpenForm "Main Menu"
.Close acForm, "Login"
Exit Sub
End With
End If

If txtPassword <> rst![Password] Then
msgbox (&quot;Password match not found. Please re-enter password to use system.&quot;)
Forms![Login]![txtPassword] = &quot;&quot;
Forms![Login]![txtPassword].SetFocus
Exit Sub
End If

Set RST = Nothing

End Sub
--------------------------------------- How many of you believe in telekinesis? Raise my hand...
Another free Access forum:
More Access stuff at
 
I tried the above with the following adaption:
Private Sub cmdSubmitLogon_Click()
Dim rst As Recordset
Rem tblusers access linked to another database on network
Set rst = CurrentDb.OpenRecordset(&quot;tblusers&quot;)
Rem set the index to strUserid field in tblusers
rst.Index = &quot;strUserid&quot;
Rem search recordset for a match from the form
rst.Seek &quot;=&quot;, Me.txtUserid

If rst.NoMatch Then
MsgBox (&quot;sorry no userid match&quot;)
Exit Sub
End If

If Me.txtPassword = rst![strPassword] Then
With DoCmd
.OpenForm &quot;frmswitchboard&quot;
.Close acForm, &quot;frmlogontest3&quot;
Exit Sub
End With
End If

The code gets an error at rst.index = &quot;strUserid&quot;
The error is &quot;runtime error 3633, can't load dll msjter35.dll&quot;
any suggestions?
Thanks.
 
Hmmmm.. Haven't really the foggiest where MSJTER35.DLL is from, probably Access/97 Jet3.5 libraries??

Is your user table indexed by the field &quot;strUserid&quot;, and it that NOT the Primary Key? See how my reference to the index is &quot;PrimaryKey&quot; - that's the name of the index used for the primary key, so you don't need to use something else, such as the field name itself.

Try again.

Jim

How many of you believe in telekinesis? Raise my hand...
Another free Access forum:
More Access stuff at
 
My 2 cents....Another way to do this would be to use the persons novel userID (in different environments this could be &quot;s_login=&quot; or maybe &quot;userid=&quot;....) with the afore mentioned User Table. This way you would not need a password but could just see who is logged in, and if they are a person who should have access to said form then let them if not then dont.

The commented out portion is also usful if you want to keep track of who has been in the database and when in a User Log table...This concept could be expanded to include recording any actions you want in your log.

Just call this function upon startup and

Public Function GetUserId()
On Error Resume Next
Dim EnvString, Indx, msg, PathLen, UserID
Indx = 1
Do

EnvString = Environ(Indx)
If Left(EnvString, 8) = &quot;s_login=&quot; Then
PathLen = Len(Environ(&quot;s_login&quot;))
UserID = Right(EnvString, PathLen)

Dim MyDB As Database, Mytable As Recordset, MyTable2 As Recordset
Set MyDB = DBEngine.Workspaces(0).Databases(0)
Set Mytable = MyDB.OpenRecordset(&quot;Users&quot;, DB_OPEN_TABLE)
Mytable.Index = &quot;UserID&quot;
Mytable.Seek &quot;=&quot;, UserID
If Not Mytable.NoMatch Then
'if user id was found then put actions here.
'Set MyTable2 = MyDB.OpenRecordset(&quot;Use Log&quot;, DB_OPEN_TABLE)
'MyTable2.Index = &quot;PrimaryKey&quot;
'MyTable2.AddNew
'MyTable2(&quot;UserId&quot;) = userid
'MyTable2(&quot;Date&quot;) = Date
'MyTable2(&quot;Time&quot;) = Time
'MyTable2(&quot;Action&quot;) = &quot;In&quot;
'MyTable2.Update
'MyTable2.Close
Else
msgbox &quot;You do not have access to this database.&quot;
'whatever action you want to take if not a
'user here, like exit database
End If

Exit Do
Else
Indx = Indx + 1
End If
Loop Until EnvString = &quot;&quot;

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top