Log-in Screen with Password Database

A

ant1983

Hi,

I'd like to add a log-in screen with username and password in my database.
Where can i get an example of such a database as im a novice with code...

Also, how can i then use the infomation entered later on in the database -
i.e. if my username is WayneS and my password is "book" and i succesfully
enter the database, how can i make access fill in (or limit) some forms where
i have to capture my name in a field.

Basically i have a booking form and different user's add bookings and one of
those fields is "Captured by" and its a drop down box of all the booking
consultants names. I'd like access to limit that choice to my name only (so
that one consultant cant capture a booking under someone else's name)
 
D

Daniel Pineault

You need tp read up on user-level security (ULS) this is already built-in to
ms access you simply need to use it/deploy it onto your database. Search
this forum for user-level security or google the term and you will find tons
of info and tutorials. Below are a few links to get you started.

http://databases.about.com/od/tutorials/ss/usersecurity.htm
http://www.geocities.com/jacksonmacd/AJMAccessSecurity.pdf
http://www.grahamwideman.com/gw/tech/access/accesssec/otherrefs.htm

Also be sure to read the follwoing MS Knowledge base (very important)
http://support.microsoft.com/support/access/content/secfaq.asp?SD=gn&LN=en-ca&gssnb=1
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.
 
C

Chris O''''Neill

ant1983 said:
I'd like to add a log-in screen with username and password in my database.
Where can i get an example of such a database as im a novice with code...

Also, how can i then use the infomation entered later on in the database -
i.e. if my username is WayneS and my password is "book" and i succesfully
enter the database, how can i make access fill in (or limit) some forms where
i have to capture my name in a field.

What you want to do is capture the username in a global variable and then
use that variable to lock/unlock and/or hide/unhide controls. I'm fairly new
to VBA too, so this might be wrong (but someone with more experience will
correct it <grin!>), but your code would go something like this:

public const strUserName = [forms]![frmLogOn]![txtUserName]

Not exactly sure where'd I'd put that... probably in the AfterUpdate event
for txtUserName on frmLogOn or something like that? Again, others will have
more info on this.
Basically i have a booking form and different user's add bookings and one of
those fields is "Captured by" and its a drop down box of all the booking
consultants names. I'd like access to limit that choice to my name only (so
that one consultant cant capture a booking under someone else's name)

Once you have the username captured in a public variable you can use it
something like this (assuming the control is a combo box)

[forms]![frmSomeForm]![cboSomeComboBox].default = strUserName

Or, better yet, get rid of the combo box (you don't need it because you only
have one name) and change it to a text field. Then do this:

[forms]![frmSomeForm]![txtSomeTextField].default = strUserName

(Note: You should disable and lock the text field (or even hide it
altogether) so that the user can't change it.)

To limit specific users from entering data into a field based on the
username, do this:

If strUsername = "Some User's Name" then
[forms]![frmSomeForm]![txtSomeTextField].Enabled = False
[forms]![frmSomeForm]![txtSomeTextField].Locked = True
Else
[forms]![frmSomeForm]![txtSomeTextField].Enabled = True
[forms]![frmSomeForm]![txtSomeTextField].Locked = False
End If

This is going to get VERY messy if you have alot of users. As well, it's
never a good idea to hard code something like a username into a program (what
if they quit or something?). A better way would be to have a table of user
rights to specific controls using Yes/No fields for the controls and then
query that table in the On_Enter event. If the user has rights to that
control, leave them there. Otherwise, use the SetFocus property to throw
them to another field. The code to do this would look something like this:

blnIsAllowed = Dlookup("ControlName","TableName", "[Username = " &
strUserName])
If blnIsAllwed = True Then
[forms]![frmSomeForm]![txtSomeField].Enabled = True
[forms]![frmSomeForm]![txtSomeField].Locked = False
Else
[forms]![frmSomeForm]![txtSomeField].Enabled = False
[forms]![frmSomeForm]![txtSomeField].Locked = True
End If

This, too, can be very messy if you have alot of controls you want to manage
or alot of users, but it's better than millions of If/Then statements all
over the place.

I hope this is helpful to you. Sorry I can't give you specific code to
solve your problem, but at least you now have some concepts to get you
started. Btw, if you do a search of this forum using "log-in" as the filter
you'll find some interesting stuff.

Have fun!

Regards, Chris
 
C

Chris O''''Neill

See? I *told* you someone with more experience would have good information
for you! (Grin!)

Seriously, though, Daniel's info is helpful to secure your application
objects (tables, forms, queries, reports, etc.). So, for instance, you can
prevent (or allow) a user from loading a particular form or report. My
information was aimed at field level security (i.e. preventing/allowing a
user from accessing a specific field). I'm not sure (but Daniel or someone
else will correct me if I'm wrong), but that can't be done using user-level
security.

Anyway, good luck with your quest! I do hope I've been a bit helpful!

Regards, Chris
 
P

pddxxx

D

dch3

Its possible to grab a person's Windows User ID and use that as the basis for
which forms they have access to - not to mention tagging who entered &
lastupdated a record.

In my implementation, I skipped the password bit on the grounds that each
person *should* be logging off of their PC when their finished with it.

If you're not implementing Access security that is an alternative. I tried
posting a rather lengthy response last night, but my browser closed my reply
unexpectedly.
 
J

Jim Burke in Novi

This statement wouldn't work:

public const strUserName = [forms]![frmLogOn]![txtUserName]

You can only set a constant to a hard-coded value, otherwise it's not a
constant. If you want to set a variable to a value that is specified on a
form or from a value in a table (or in this case to a value access may know
if you're using security) etc. you would use a public variable. So somewhere
in a 'global' module you would have

public strUserName as String

then in code that runs when the appl starts or when a form is opened,
whenever you need it set, you would then have

strUserName = [forms]![frmLogOn]![txtUserName]

or if using Access security, I think it would be

strUserName = Application.CurrentUser

Chris O''''Neill said:
ant1983 said:
I'd like to add a log-in screen with username and password in my database.
Where can i get an example of such a database as im a novice with code...

Also, how can i then use the infomation entered later on in the database -
i.e. if my username is WayneS and my password is "book" and i succesfully
enter the database, how can i make access fill in (or limit) some forms where
i have to capture my name in a field.

What you want to do is capture the username in a global variable and then
use that variable to lock/unlock and/or hide/unhide controls. I'm fairly new
to VBA too, so this might be wrong (but someone with more experience will
correct it <grin!>), but your code would go something like this:

public const strUserName = [forms]![frmLogOn]![txtUserName]

Not exactly sure where'd I'd put that... probably in the AfterUpdate event
for txtUserName on frmLogOn or something like that? Again, others will have
more info on this.
Basically i have a booking form and different user's add bookings and one of
those fields is "Captured by" and its a drop down box of all the booking
consultants names. I'd like access to limit that choice to my name only (so
that one consultant cant capture a booking under someone else's name)

Once you have the username captured in a public variable you can use it
something like this (assuming the control is a combo box)

[forms]![frmSomeForm]![cboSomeComboBox].default = strUserName

Or, better yet, get rid of the combo box (you don't need it because you only
have one name) and change it to a text field. Then do this:

[forms]![frmSomeForm]![txtSomeTextField].default = strUserName

(Note: You should disable and lock the text field (or even hide it
altogether) so that the user can't change it.)

To limit specific users from entering data into a field based on the
username, do this:

If strUsername = "Some User's Name" then
[forms]![frmSomeForm]![txtSomeTextField].Enabled = False
[forms]![frmSomeForm]![txtSomeTextField].Locked = True
Else
[forms]![frmSomeForm]![txtSomeTextField].Enabled = True
[forms]![frmSomeForm]![txtSomeTextField].Locked = False
End If

This is going to get VERY messy if you have alot of users. As well, it's
never a good idea to hard code something like a username into a program (what
if they quit or something?). A better way would be to have a table of user
rights to specific controls using Yes/No fields for the controls and then
query that table in the On_Enter event. If the user has rights to that
control, leave them there. Otherwise, use the SetFocus property to throw
them to another field. The code to do this would look something like this:

blnIsAllowed = Dlookup("ControlName","TableName", "[Username = " &
strUserName])
If blnIsAllwed = True Then
[forms]![frmSomeForm]![txtSomeField].Enabled = True
[forms]![frmSomeForm]![txtSomeField].Locked = False
Else
[forms]![frmSomeForm]![txtSomeField].Enabled = False
[forms]![frmSomeForm]![txtSomeField].Locked = True
End If

This, too, can be very messy if you have alot of controls you want to manage
or alot of users, but it's better than millions of If/Then statements all
over the place.

I hope this is helpful to you. Sorry I can't give you specific code to
solve your problem, but at least you now have some concepts to get you
started. Btw, if you do a search of this forum using "log-in" as the filter
you'll find some interesting stuff.

Have fun!

Regards, Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top