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

trouble creating login in excel

P: 9
i have created a database using excel and i have to set a security level i have written all of the vba code correctly i think but it just does seem to work properly. here is the code below if anyone could point out any problems with it would be much appreciated.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Login_Click()
  3. Dim name, password, found, loops
  4.   found = 0
  5.   loops = 0
  6.   name = Range("Username").Value
  7.   password = Range("Password").Value
  8.   Worksheets("Data").Visible = True
  9.   Worksheets("Data").Select
  10.   ActiveSheet.Range("A1").Activate
  11.   While ActiveCell.Offset(loops, 0).Value <> "" And found = 0
  12.     If Username = ActiveCell.Offset(loops, 0).Value Then
  13.       If password = ActiveCell.Offset(loops, 1).Value Then
  14.         found = 1
  15.       End If
  16.     End If
  17.     loops = loops + 1
  18.   Wend
  19.   If found = 0 Then
  20.     Worksheets("Login").Select
  21.     Worksheets("Data").Visible = True
  22.     MsgBox ("Logon Failed")
  23.     Worksheets("Lowlev").Visible = False
  24.     Workbooks("Unit10assisgnment.xls").Close SaveChanges:=False
  25.   End If
  26.   Worksheets("Lowlev").Visible = True
  27.   Worksheets("Lowlev").Select
  28.   ActiveWindow.DisplayWorkbookTabs = True
  29.  
  30. End Sub
  31.  
Nov 15 '06 #1
Share this Question
Share on Google+
2 Replies


100+
P: 1,646
i have created a database using excel and i have to set a security level i have written all of the vba code correctly i think but it just does seem to work properly. here is the code below if anyone could point out any problems with it would be much appreciated.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Login_Click()
  3. Dim name, password, found, loops
  4.   found = 0
  5.   loops = 0
  6.   name = Range("Username").Value
  7.   password = Range("Password").Value
  8.   Worksheets("Data").Visible = True
  9.   Worksheets("Data").Select
  10.   ActiveSheet.Range("A1").Activate
  11.   While ActiveCell.Offset(loops, 0).Value <> "" And found = 0
  12.     If Username = ActiveCell.Offset(loops, 0).Value Then
  13.       If password = ActiveCell.Offset(loops, 1).Value Then
  14.         found = 1
  15.       End If
  16.     End If
  17.     loops = loops + 1
  18.   Wend
  19.   If found = 0 Then
  20.     Worksheets("Login").Select
  21.     Worksheets("Data").Visible = True
  22.     MsgBox ("Logon Failed")
  23.     Worksheets("Lowlev").Visible = False
  24.     Workbooks("Unit10assisgnment.xls").Close SaveChanges:=False
  25.   End If
  26.   Worksheets("Lowlev").Visible = True
  27.   Worksheets("Lowlev").Select
  28.   ActiveWindow.DisplayWorkbookTabs = True
  29.  
  30. End Sub
  31.  
Hi. Perhaps the thing that is most evident here is the last part of your code
Expand|Select|Wrap|Line Numbers
  1. If found = 0 Then
  2.     Worksheets("Login").Select
  3.     Worksheets("Data").Visible = True
  4.     MsgBox ("Logon Failed")
  5.     Worksheets("Lowlev").Visible = False
  6.     Workbooks("Unit10assisgnment.xls").Close SaveChanges:=False
  7.   End If
  8.   Worksheets("Lowlev").Visible = True
  9.   Worksheets("Lowlev").Select
  10.   ActiveWindow.DisplayWorkbookTabs = True
  11.  
Can you explain what this line does?
Workbooks("Unit10assisgnment.xls").Close SaveChanges:=False
Nov 16 '06 #2

P: 9
whne the incorrect details have been entered it will close the workbook and i choose whether i want to save the changes that have made to the workbook before it closes.

i have to set to false so it doesnt save the changes that have been made when the wrong password and username are entered.
Nov 16 '06 #3

Post your reply

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