By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,649 Members | 696 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,649 IT Pros & Developers. It's quick & easy.

Can a button check password and filter?

P: 27
Sorry to bother you all again...
I am trying to create a login page where upon inputting the correct UserName AND password, it would filter a subform below so that they could see only their comments. Is this possible? I have it so that there are two buttons where one checks the Username and Password via VBA code and another button filters using a Macro... But I would like for one button to do everything so that if the password is incorrect, then they cannot see anything. The filter button currently works without a password and as long as there is a correct username it will filter that without looking at the password. I was thinking about just having it click the other button at the end?

I want to say this works but it doesn't after line 25

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub btnLogin_Click()
  5.     Dim rs As Recordset
  6.  
  7.         Set rs = CurrentDb.OpenRecordset("tbl1Employees", dbOpenSnapshot, dbReadOnly)
  8.  
  9.     rs.FindFirst "UserName='" & Me.txtUserName & "'"
  10.  
  11.     If rs.NoMatch Then
  12.         Me.lblWrongUser.Visible = True
  13.         Me.txtUserName.SetFocus
  14.         Exit Sub
  15.     End If
  16.     Me.lblWrongUser.Visible = False
  17.  
  18.     If rs!Password <> Nz(Me.txtPassword, "") Then
  19.         Me.lblWrongPass.Visible = True
  20.         Me.txtPassword.SetFocus
  21.         Exit Sub
  22.     End If
  23.     Me.lblWrongPass.Visible = False
  24.  
  25.     ' Dim SQL As String
  26.     'SQL = "SELECT tbl1Comments.comment, tbl1Comments.CommentDate, tbl1Comments.Followup" _
  27.      '& "FROM tbl1Comments;"
  28.     'Me.subComment.Form.RecordSource = SQL
  29.     'Me.subComment.Form.Requery
  30.     Dim search_text As String
  31.     search_text = Me.txtUserName
  32.  
  33.     If Nz(Me.txtUserName.Value, "") = "" Then
  34.         Me.FilterOn = False
  35.         Me.txtUserName.SetFocus
  36.         Exit Sub
  37.     End If
  38.     Me.Filter = "UserName like '*" & Me.txtUserName.Value & "*' or userName like '*"
  39.     Me.FilterOn = True
  40.     Me.txtUserName.SetFocus
  41.     Me.txtUserName.Value = search_text
  42.     Me.txtUserName.SelStart = Len(Nz(Me.txtUserName.Value, "")) & 1
  43.  
  44. End Sub
  45.  
  46.  
Feb 26 '19 #1
Share this Question
Share on Google+
5 Replies


twinnyfo
Expert Mod 2.5K+
P: 3,277
Beginner,

1. You're no so much of a beginner after all...

2. Do not EVER save passwords in your database unless they are encrypted. Better yet: do not EVER save passwords in your database.

3. If you want User-specific productivity in your DB, take a good, long look at this Article on Creating User Permissions in an Access Database. Yes, it is a bit much to chew on, but I have been using this for many years, and it is the best way for you to keep out of the username and password business and leave that up to your network folks. Once you know who is using your DB, you can control all forms based on that user.

4. I admit, I have not looked at your code much, mainly because of point number 2 above.

Hope this hepps!
Feb 27 '19 #2

P: 27
Dear twinnyfo,

Thank you for the compliment! I actually have been taking bits of other people's code and putting them together

Do you think it will be ok to have a separate database that holds just the comments for the employees separately? I was planning to have the tables perhaps linked to another database in which they would need access to. That way they cannot look up other people's password and can only see their filtered data.

I figured out how to do it. I made a macro and made it run macro at the end of the code that way it can go through the username and password first then do the macro of filtering the data. :)
Feb 27 '19 #3

twinnyfo
Expert Mod 2.5K+
P: 3,277
If you took a look at the article, you would see that if you are able to identify the user, based upon their system login credentials, you can then use the User data to filter your forms so they can only see what you want them to see. This is not limited to switchboard menus (as described in the artcle), but can apply to all manner of data. As long as you associate a user's ID with a record, you can filter by User ID.

Make sense?

Again, trying to gently convince you that saving passwords in your DB (in any way) is not hte best way to go. If you must, make sure it is encrypted--and encryption is not my strong suit, but there are several experts who really understand the principles better.

My method is a great place to start. The only way this would not work is if you have an "open" machine that multiple users gain acces to but don't have to log into "the machine"--which again, is not wise.
Feb 27 '19 #4

P: 27
Thank you for your quick reply!

Ok I will look further into User-specific productivity. I may have questions in a bit, but I will try my best to understand!
Feb 27 '19 #5

twinnyfo
Expert Mod 2.5K+
P: 3,277
Great - standing by to assist with any additional questions....
Feb 27 '19 #6

Post your reply

Sign in to post your reply or Sign up for a free account.