Guest User

Untitled

a guest
Aug 2nd, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2. '******************************************************************************************************
  3. 'Structure into which the data from the database is loaded.
  4. Dim rst As New ADODB.Recordset 'Makes a new recordset
  5. '****************************************************************
  6. Dim DatabasePath As String 'Path of the database
  7. '****************************************************************
  8. Dim SRSQL As String 'This is language used to manipulate the data by making a new connection string
  9. '****************************************************************
  10. Dim SRLoc As String 'Location of database
  11. Dim ExitSystem As String 'Exits the program
  12. Dim Message As String
  13.  
  14. Private Sub cmdBack_Click()
  15. '******************************************************************************************************
  16. 'Returns the user to their previous form
  17. '******************************************************************************************************
  18. Unload Me 'Stops the program instead of hiding the form
  19. MainMenu.Show 'Opens the Main Menu form
  20. End Sub
  21.  
  22. '******************************************************************************************************************************************
  23. 'Login
  24. '******************************************************************************************************************************************
  25. Private Sub cmdLogin_Click()
  26.  
  27. Dim SearchUsername As String
  28. Dim SearchPassword As String
  29.  
  30. 'Verifies the Login with the Database
  31. SRLoc = App.Path & "\SandwichOrder.mdb" 'Location of Database
  32. StringConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & SRLoc
  33.  
  34. SearchUsername = txtUsername.Text
  35. SearchPassword = txtPassword.Text
  36. SRSQL = "SELECT * FROM tblCustomerDetails WHERE Username = " & "'" & SearchUsername & "'" & " And Password = " & "'" & SearchPassword & "'" & ""
  37.  
  38. 'Makes a SQL
  39.      databaseconnection.ConnectionString = StringConnectionString
  40.       databaseconnection.Open
  41.  
  42.      
  43. With rst
  44. .ActiveConnection = databaseconnection
  45. .LockType = adLockOptimistic
  46. .CursorType = adOpenKeyset
  47.     .Open SRSQL
  48.     'Test for a valid user
  49.    If .EOF Then
  50.     'Message Box to show incorrect username or password
  51.        MsgBox "The Username or Password you have entered is incorrect", vbCritical
  52.     Exit Sub
  53.     End If
  54.  
  55. End With
  56. Username = txtUsername.Text
  57. Unload Me 'Stops the program instead of hiding the form
  58. Order.Show 'Opens the order form
  59. Order.cmbBreadType.Text = "Please Select Bread Type"
  60. Order.cmbBreadSize.Text = "Please Select Bread Size"
  61. Order.cmbFilling.Text = "Please Select Filling"
  62. Order.cmbDrinks.Text = "Please Select Drink(s)"
  63.  
  64.  
  65. End Sub
  66.  
  67. Private Sub txtPassword_LostFocus() 'Lost focus has to be set to make the password work
  68. txtPassword.Text = Replace(txtPassword.Text, " ", "")
  69. End Sub
  70.  
  71. Private Sub cmdClose_Click()
  72. '******************************************************************************************************
  73. 'Closes project
  74. '******************************************************************************************************
  75.    
  76. 'Message Box asking the user if they want to exit the system
  77. Message = MsgBox("Are you sure you want to exit?", vbYesNoCancel + vbCritical, "Exit")
  78. If Message = vbYes Then
  79. End
  80. End If
  81.  
  82. End Sub
  83. '******************************************************************************************************************************************
  84. 'Format Password Textbox
  85. '******************************************************************************************************************************************
  86. Private Sub txtPassword_GotFocus()
  87. txtPassword.PasswordChar = "*"
  88. txtPassword.Text = ""
  89. End Sub
  90. '******************************************************************************************************************************************
  91. 'Format Username Textbox
  92. '******************************************************************************************************************************************
  93. Private Sub txtUsername_GotFocus()
  94. txtUsername.Text = ""
  95. End Sub
  96.  
  97. Private Sub txtUsername_LostFocus() 'Lost focus has to be set to make the username work
  98. txtUsername.Text = Replace(txtUsername.Text, " ", "")
  99. End Sub
  100.  
  101. Private Sub Form_Load()
  102. '******************************************************************************************************
  103. 'Loads form
  104. '******************************************************************************************************
  105. Me.Left = (Screen.Width - Me.Width) / 2 'Centres the form
  106. Me.Top = (Screen.Height - Me.Height) / 2 'Centres the form
  107. End Sub
  108.  
  109. Private Sub Form_Unload(Cancel As Integer)
  110. '******************************************************************************************************
  111. 'Unloads Form
  112. '******************************************************************************************************
  113. rst.Close
  114. Set rst = Nothing
  115. databaseconnection.Close
  116. End Sub
Add Comment
Please, Sign In to add comment