trouble creating login in excel

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • squidge1990
    New Member
    • Nov 2006
    • 9

    #1

    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.

    Code:
     
    Private Sub Login_Click()
    Dim name, password, found, loops
      found = 0
      loops = 0
      name = Range("Username").Value
      password = Range("Password").Value
      Worksheets("Data").Visible = True
      Worksheets("Data").Select
      ActiveSheet.Range("A1").Activate
      While ActiveCell.Offset(loops, 0).Value <> "" And found = 0
    	If Username = ActiveCell.Offset(loops, 0).Value Then
    	  If password = ActiveCell.Offset(loops, 1).Value Then
    		found = 1
    	  End If
    	End If
    	loops = loops + 1
      Wend
      If found = 0 Then
    	Worksheets("Login").Select
    	Worksheets("Data").Visible = True
    	MsgBox ("Logon Failed")
    	Worksheets("Lowlev").Visible = False
    	Workbooks("Unit10assisgnment.xls").Close SaveChanges:=False
      End If
      Worksheets("Lowlev").Visible = True
      Worksheets("Lowlev").Select
      ActiveWindow.DisplayWorkbookTabs = True
     
    End Sub
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Originally posted by squidge1990
    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.

    Code:
     
    Private Sub Login_Click()
    Dim name, password, found, loops
      found = 0
      loops = 0
      name = Range("Username").Value
      password = Range("Password").Value
      Worksheets("Data").Visible = True
      Worksheets("Data").Select
      ActiveSheet.Range("A1").Activate
      While ActiveCell.Offset(loops, 0).Value <> "" And found = 0
    	If Username = ActiveCell.Offset(loops, 0).Value Then
    	  If password = ActiveCell.Offset(loops, 1).Value Then
    		found = 1
    	  End If
    	End If
    	loops = loops + 1
      Wend
      If found = 0 Then
    	Worksheets("Login").Select
    	Worksheets("Data").Visible = True
    	MsgBox ("Logon Failed")
    	Worksheets("Lowlev").Visible = False
    	Workbooks("Unit10assisgnment.xls").Close SaveChanges:=False
      End If
      Worksheets("Lowlev").Visible = True
      Worksheets("Lowlev").Select
      ActiveWindow.DisplayWorkbookTabs = True
     
    End Sub
    Hi. Perhaps the thing that is most evident here is the last part of your code
    Code:
    If found = 0 Then
    	Worksheets("Login").Select
    	Worksheets("Data").Visible = True
    	MsgBox ("Logon Failed")
    	Worksheets("Lowlev").Visible = False
    	Workbooks("Unit10assisgnment.xls").Close SaveChanges:=False
      End If
      Worksheets("Lowlev").Visible = True
      Worksheets("Lowlev").Select
      ActiveWindow.DisplayWorkbookTabs = True
    Can you explain what this line does?
    Workbooks("Unit 10assisgnment.x ls").Close SaveChanges:=Fa lse

    Comment

    • squidge1990
      New Member
      • Nov 2006
      • 9

      #3
      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.

      Comment

      Working...