having problem with code

neomod

New Member
Joined
Apr 3, 2002
Messages
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?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,557
Messages
6,114,288
Members
448,563
Latest member
MushtaqAli

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top