Change UserName & Password from Worksheet,

S

Shazi

Hi,

I am developing a vba program for store inventory, it has many sheets
and userforms.

on opening of the workbook one userform is displaying and asking for
the User Name and Password, if it is ok then OK button opens all the
very hidden worksheets.

Textbox1 = Shahzad (username)
Textbox2 = Hilton (password)

My procedure is given below in the UserForm:

My problem is this when ever I want to change the UserName and
Password, i have to open VBA Editor, and open userform for Login, then
I can change the username and password. Instead of doing all this
things, I want to give access to the User to change his username and
password himself.

So, I want to do this from worksheet, here I want to tell you when my
user close the workbook, all sheets are gone very hidden, only Welcome
sheet remaining.

I arrange an other sheet to change the user neme and password.

Sheet name = ChangeUser
B5 = Shahzad (user name)
B6 = Hilton (password)

Now If I change the cell B5 and B6 then it will make the changes
into UserLogin Form. which is given below.

If it is possible then pls send me the solution, I will he thankful to
you.

Best Regards.


Shahzad


My User Log in Function is given below.
------------------------------------------------------

Public cntr As Integer

Private Sub CommandButton2_Click()
' Call sub to validate the password entry
ValidatePWD
End Sub

Private Sub CommandButton4_Click()
UserLogin.Hide
Admin.Show
End Sub

Private Sub UserForm_Activate()
' Set the counter to 0 when the userform activates
cntr = 0
' Set the password character for textbox22 to an asterisk
TextBox2.PasswordChar = "*"
' Set the caption for the CommandButton
CommandButton2.Caption = "Open"
End Sub

Private Sub ValidatePWD()
' Sub to validate the username and password entry.
' If both match, then hide the userform and call

If TextBox1.Value = "shahzad" And _
TextBox2.Value = "hilton" Then

'jobs on opening time

UserLogin.Hide

Application.ScreenUpdating = False

Worksheets("DailyPurchase").Visible = True
Worksheets("DailyIssue").Visible = True
Worksheets("MonthlyPurchase").Visible = True
Worksheets("MonthlyIssue").Visible = True
Worksheets("Category").Visible = True
Worksheets("Employee").Visible = True
Worksheets("Lists").Visible = True
Worksheets("InventoryReport").Visible = True
Worksheets("ReportIssue").Visible = True
Worksheets("ReportPur").Visible = True
Worksheets("Blank").Visible = True
Worksheets("InventoryReport Backup").Visible = True
Worksheets("About").Visible = True
Worksheets("Sheet1").Visible = True
Worksheets("Admin").Visible = xlVeryHidden

Application.ScreenUpdating = True

Sheets("About").Select
Range("A1").Select

MainMenu.Show

Else
' Increment the counter by one
cntr = cntr + 1
' Check to see if the user has unsuccessfuly
' entered an incorrect username or password
' more than three times. If so, display a
' message box and close the workbook.
If cntr > 3 Then
MsgBox "Sorry...invaled password...goodbye"
' for normal excel
Application.CommandBars("Worksheet Menu Bar").Enabled = True
Application.DisplayFullScreen = False
' Application.CommandBars("Full Screen").Visible = False
Windows(ThisWorkbook.Name).Visible = True

'close file without asking yes/no question.

ThisWorkbook.Close False

Unload Me

Else
' Warn user that username and/or password is incorrect
MsgBox " Attempt #" & cntr & vbCrLf & _
"Incorrect UserName and/or Password entered"
End If
End If
End Sub

Private Sub CommandButton5_Click()
Call UserForm_Initialize
End Sub
Private Sub CommandButton3_Click()

' for normal excel
Application.CommandBars("Worksheet Menu Bar").Enabled = True
Application.DisplayFullScreen = False
' Application.CommandBars("Full Screen").Visible = False
Windows(ThisWorkbook.Name).Visible = True

' close file without asking yes/no question.

ThisWorkbook.Close False
Unload Me

End Sub

Private Sub cmdClearForm_Click()
Call UserForm_Initialize
End Sub
Private Sub UserForm_Initialize()
TextBox1.Value = ""
TextBox2.Value = ""
TextBox1.SetFocus
End Sub


Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)
' Disable the "X" on the userform so that the user can't

If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox Prompt:=" Sorry but I can't let you do that. "
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top