![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Apr 2002
Posts: 6
|
This code is for a password useform that pops upupon opening a workbook.
Private Sub CommandButtonpassword1_Click() Static intcount As Integer Dim strpassword As String Dim strpasswordmatch As String intcount = intcount + 1 If intcount > 2 Then intcount = 0 MsgBox "You Are Not Authorized To Use This Program! Please Contact Your System Administrator For Access!", vbCritical, "Unknown User" ActiveWorkbook.Close Exit Sub End If passwordcheck End Sub Sub passwordcheck() strpassword = frmpassword1.textboxpassword1.Value strpasswordmatch = Sheets("Valid Users").Range("c2").Value If strpassword = strpasswordmatch Then frmpassword1.Hide Else frmpassword1.textboxpassword1.Value = "" MsgBox "I'm Sorry, That Password Is Incorrect. Please Try Again!", vbCritical, "Invalid Password!" frmpassword1.textboxpassword1.SetFocus End If End Sub This works great if I manualy set passwordcheck. Example: passwordcheck = "123456" but if I have it try to use the value of cell c2 on the valid users page, it doesn;t work. what am I doing wronge? |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
A shot in the dark:
Change these two lines of your code: strpasswordmatch = Sheets("Valid Users").Range("c2").Value If strpassword = strpasswordmatch Then To This: strpasswordmatch = Trim(Sheets("Valid Users").Range("c2").Value) If Trim(strpassword) = strpasswordmatch Then Let us know... Tom Appended: Change: strpassword = frmpassword1.textboxpassword1.Value To: strpassword = frmpassword1.textboxpassword1.Text [ This Message was edited by: TsTom on 2002-04-04 19:39 ] |
|
|
|
|
|
#3 |
|
New Member
Join Date: Apr 2002
Posts: 6
|
That worked great Tom.
now if you can help me out a little more with this. What I want to do is expand the range from ("c2") to let's say ("c2:c27") what I mean is I want to have the possibility of having 25 people able to access the workbook each with their indivitual password so how can I have the code scan the range and see if the password inputed into the text box matches any of the cell values in the range at the same time ignoring blank cells as to not allow access if someone does not input anything since that would match an empty cell? P.S. I guess the blank cell issue although I would like to have a way of doing it with leaving them blank is not the biggest deal of this thing, I guess if need be, I could fill all the blank cells of the range in with a password only I would know and change it if I add a user. Thanks |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|