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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User login and limitations

Status
Not open for further replies.

jnp102

Technical User
Mar 22, 2004
19
0
0
US
Ok, I've got this partially working but can't get it the rest of the way for some reason. I have a login form that has a drop down menu with everyones user id in it, then a password field to input their password. I already have the validation code set and that works fine. Where my problem lies is with restricting buttons on the main form. I have the following code on the "onload" function of the main form that opens up after the login validation.

Private Sub Form_Load()

Admin = DLookup("[Group]", "login", "UserID = '" & (Combo11) & "'")
Super = DLookup("[Group]", "login", "UserID = '" & (Combo11) & "'")

If Nz(Admin) = Admin Then
Me.update.Visible = False
End If

If Nz(Super) = Super Then
Me.update.Visible = True
End If

End Sub

I should mention that I have a table that has 3 fields in it....UserID, Password and Group. This where the validation looks to see if the userid and the password is. I want the "onload to go into this table, look at the userid that was logged in and check what group they are associated with. From there limit the buttons based off of the group the user is associated with. The above code still makes the update button visible to anyone. However if I take out the second if statement it works perfectly. Unfortunately I need multiple if statements. Also, I can not use the code to grab the NT userid because of traveling purposes. Any help would be greatful.


Thanks
jnp102
 
my immediate response would be to nest the "if"'s


as a sugestion you could always bind the login form to the table

switch on the wizard and drop a combo box on form, select option 3 for select record based on combo box value.

just drop the text boxes for other fields and hide em

this would let you do some fancy things like keeping a record of "last logged in" dates for each user by putting a bit of vba behind the combos after update. or only allowing one instance of database by having a "logged in" boolean field and a few other things i can think of that might be of use. logged on from <computer name> etc etc etc
 
That would be nice to keep track of some of that stuff but I need the validation part of it. However, if you could....explain the nesting of the "ifs" a little further if you could. The interesting part about what I have already is that it seems like it is just looking in the table to see if the word Admin or Super is in the column and granting whatever. I need it to only use the Group access that is associated with the UserID that logged in.


Thanks
Jnp102
 
What about something like this ?
Private Sub Form_Load()
grp = DLookup("[Group]", "login", "UserID = '" & Combo11 & "'")
If Nz(grp) = "Admin" Then
Me.update.Visible = False
End If
If Nz(grp) = "Super" Then
Me.update.Visible = True
End If
End Sub

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV,

I changed the code to what you have and it still just "kind of works". Now it takes the first If statement and just holds it true for everyone that logs in. So basically it looks like it is not reading the second statement at all. Any other suggestions?



Thanks
jnp102
 
Private Sub Form_Load()
grp = DLookup("[Group]", "login", "UserID = '" & Combo11 & "'")
If Nz(grp) = "Admin" Then
Me.update.Visible = False
else If Nz(grp) = "Super" Then
Me.update.Visible = True
End If
End Sub

thats a nested "if"
 
sillysod,

I tried to put that in there but I get an error when I go to the next line down "Compile Error: Must be first statement on the line" and the following line is in red....

Else If Nz(grp) = "Super" Then

Maybe I'm just missing something but I can't get it to happen for me. Any other help would be great.

Thanks
jnp102
 
Else If Nz(grp) = "Super" Then
Get rid of the space between the Else and the If words, like this:
ElseIf Nz(grp) = "Super" Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV,

Ok, sorry, I should have known that I just wasn't thinking about it. Anyway, it still did not work which ok for now, I've went another route because I have to have something soon. No matter if I had someone as admin or super the button was not hiding. However, if anyone comes up with anything else it would be great because this is how I would ultimately like to do it.


Thanks again
jnp102
 
You have to post the definition of the login table and the values stored in the Group column.
Another way is to have the RowSource of Combo11 grabbing all the necessary info into hidden columns.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top