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