467,161 Members | 876 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,161 developers. It's quick & easy.

trouble creating login in excel

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
  • viewed: 1720
Share:
2 Replies
1GB
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
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.

Similar topics

6 posts views Thread by Jeremy Langworthy | last post: by
5 posts views Thread by Guy Incognito | last post: by
reply views Thread by ketz | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.