First off, everything I know about programming databases I've either read in various books, taught myself, or learned from you guys on this form. So my apologies in advance if this is a dumb question.
I have a table in a database that has a list of users. I also have a form that is used to add records to another table (the primary information table). The database is accessible to many people on the network, but I only want certain people (that are in the users table) to be able to add a record to the information table using the aforementioned table.
I used this site to capture the user's login (which is a field in the user's table).
My question is, what kind of code do I use to check this name against the table?
The table is constantly changing, so I don't want to do a
If usersname = nameA or usersname = nameB ... 'deny access end if
because then I would have to change the code every time I change the table (which seems to be a waste of time and energy). It seems there has to be a way, I just don't know it.
Right then, now you create a roll called "Form Access" or whatever it is. Then:
If DCount("user_role_id", tblUserRoles, "user_id = " & MyUserId & " AND role_id = " & MyRoleId) > 0 Then
'None for you!
If you want to get REALLY crazy, you can add a group role schema that sits along side that as well. Then create a user object that populates a collection of available roles based on the combined list of roles available to that particular user, as well as any groups that user is a member of.
The simpler way is to use a DCount; the more efficient way is to open a recordset. In either case you include a criteria of that user, so nothing is returned if they aren't in the table. Then test for that.