user form error

niailmar

New Member
Joined
May 22, 2012
Messages
11
Hello everyone.
I've one problem about creating user form. I found an example about creating password and implement it into my system. And in another sheet , I already create a list for username and password as reference.


Refer from image attached, after user click the button of Guarantee Letter, the login (password required) form will popup. The problem is the selected username a not showing.


The second is, login (new password) also have a problem like attached image. I'm not sure whether I put the wrong reference code or using the wrong selected object.


Please help me. Thank so much
attachment.php
 

Some videos you may like

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

repairman615

Well-known Member
Joined
Dec 21, 2009
Messages
1,885
Hello,

Welcome to the Board!


Please post your code. Also, when choosing 'Debug' after the error please tell which line is highlighted.
 

niailmar

New Member
Joined
May 22, 2012
Messages
11
code for password required
Code:
Private Sub Cancel_Click()
'Sheets("Protected").Visible = xlVeryHidden
MsgBox "Password Not Entered.  Workbook will close!"
Unload Me
ThisWorkbook.Close
End Sub


Private Sub EnterPassword_Click()
Dim password As String
password = PasswordInput.Text




If password = WorksheetFunction.VLookup(UserList.Value, Range("Users_List"), 2, 0) Then
'Sheets("Protected").Visible = xlVeryHidden
'Sheets("Blank").Visible = xlVeryHidden
MsgBox "Password Accepted"
Unload Me
Else
'Sheets("Protected").Visible = xlVeryHidden
'Sheets("Blank").Visible = xlVeryHidden
MsgBox "Password Not Accepted, Workbook will close"
Unload Me
ThisWorkbook.Close
End If






End Sub


Private Sub UpdatePassword_Click()
Dim password As String
password = PasswordInput.Text
If password = WorksheetFunction.VLookup(UserList.Value, Range("Users_List"), 2, 0) Then
User = UserList.Value
Sheets("Blank").Range("A1").Value = User
Unload Me
UserForm2.Show
Else
MsgBox "Passwords do not match, please try again"
End If






End Sub






Private Sub UserForm_Terminate()
Dim password As String
password = PasswordInput.Text


If PasswordInput.Text = "" Or UserList.Value = "" Then


MsgBox "must use this form, workbook will close"
ThisWorkbook.Close
ElseIf password = WorksheetFunction.VLookup(UserList.Value, Range("Users_List"), 2, 0) Then






End If
End Sub


code for new password
Code:
Private Sub CommandButton1_Click()


Dim password As String


password = TextBox1.Text
secondpassword = TextBox2.Text


If password = secondpassword Then


With Worksheets("Protected").Range("Users")
    Set c = .Find(Sheets("Blank").Range("A1").Value, LookIn:=xlValues)
    If Not c Is Nothing Then
        Sheets("Protected").Range(c.Address).Offset(0, 1).Value = password
    Sheets("Protected").Visible = xlVeryHidden
    Sheets("Blank").Visible = xlVeryHidden
MsgBox "Password Updated"


Unload Me
Sheets("Blank").Range("A1").Value = ""
    End If
End With


Else
MsgBox "Passwords do not match, please try again"
End If








End Sub






Private Sub TextBox1_Change()


End Sub


Private Sub TextBox2_Change()


End Sub


Private Sub UserForm_Terminate()
Dim User As String


User = Sheets("Blank").Range("A1").Value


If TextBox1.Value = WorksheetFunction.VLookup(User, Range("Users_List"), 2, 0) Then


Else
MsgBox "must use this form, workbook will close"
ThisWorkbook.Close
End If
End Sub
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets("Blank").Visible = xlSheetVisible
End Sub


Private Sub Workbook_Open()
If Sheets("Blank").Visible <> xlSheetVisible Then
Sheets("Blank").Visible = xlSheetVisible
End If
Sheets("Blank").Select
Application.ScreenUpdating = False
Application.DisplayAlerts = False


Sheets("Protected").Visible = xlSheetVisible
UserForm1.Show
End Sub

the highlighted code that occur an error serving
debug is...
If TextBox1.Value = WorksheetFunction.VLookup(User, Range("Users_List"), 2, 0) Then


thak you..:)
 
Last edited:

repairman615

Well-known Member
Joined
Dec 21, 2009
Messages
1,885
Try replacing the line:

If TextBox1.Value = WorksheetFunction.VLookup(User, Range("Users_List"), 2, 0) Then

With:

Rich (BB code):
If TextBox1.Value = WorksheetFunction.VLookup(User, Range("[highlight]YourWorkbookName.xlsm[/highlight]!Users_List"), 2, 0) Then

Change YourWorkbookName.xlsm to your actual workbook name and extension.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,214
Messages
5,594,881
Members
413,947
Latest member
gizmolucy

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
Top