PDA

Click to See Complete Forum and Search --> : Login Help


tanker
Oct 2nd, 2000, 02:10 PM
I used the wizard in VB to create a login to limit access to the application via a username and password, but it doesn't work correctly. Does someone have an example I could look at.

VBOB
Oct 3rd, 2000, 11:56 AM
Public Sub GetDBPath()

'The subroutine to open access database

Open "location.ini" For Input As #1
Open "system.ini" For Input As #2
Input #1, pth
Input #2, sys
Close #1
Close #2
dbPath = pth
sysPath = sys
DBEngine.SystemDB = sysPath
DBEngine.DefaultUser = "username"
DBEngine.DefaultPassword = "password"

Set dbs = OpenDatabase(dbPath)
Exit Sub

errorhandler:
Stop
End Sub
_________________________________________________

Private Sub cmdOK_Click()

'Design the login screen (2 cmd buttons/1 txt box/1 combo
'Select the Department from combo box.
'type password into txtbox

Screen.MousePointer = vbHourglass
pass = txtPassword.Text
Group = cboDept.text
GetDBPath 'calls the routing above to open the database

'check the password

Set passrec = dbs.OpenRecordset("Select [Password] FROM tbl_pass WHERE [Department]='" & Group & "'")

passtemp = passrec![Password]
dbs.Close


If UCase(pass) = UCase(passtemp) Then
enable menus / show forms etc...
Else
Unload frmLogin
disable menus / show forms etc...
End If

Screen.MousePointer = vbDefault
End Sub

____________________________________________
Bob

PS. I hope I haven't misunderstood your request entirely !!

tanker
Oct 3rd, 2000, 02:32 PM
How can I set security levels?

VBOB
Oct 4th, 2000, 02:39 AM
Just add a field to your database [Security Levels] and depending on who logs in and what security level they are you enable more or less functionality.
Bob

tanker
Oct 4th, 2000, 09:55 AM
What is the code to use the username to determine security levels if my table is called security?

VBOB
Oct 4th, 2000, 10:25 AM
The code is very similar to what I have posted earlier ... It will depend on whether you are limiting access by User or by Department.
Add a field [Access Level] to the table that stores the Usernames/Depts/Passwords then read it into the Recordset and then perform actions depending on the value stored in the [Access Level] field

ie..... use the earlier code but amend to something like this....


.......
.......
GetDBPath 'calls the routing above to open the database

Set passrec = dbs.OpenRecordset("Select * FROM tbl_pass WHERE [Department]='" & Group & "'")

passtemp = passrec![Password]
accessvar = passrec![Access Level]
dbs.Close


If UCase(pass) = UCase(passtemp) Then
Select Case accessvar
Case accessvar = 1
.........
Case accessvar = 2
.........
Case accessvar = 3
.........
End Select
Else
Unload frmLogin
disable menus / show forms etc...
End If

Screen.MousePointer = vbDefault


____________________________________________________