Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- '******************************************************************************************************
- 'Structure into which the data from the database is loaded.
- Dim rst As New ADODB.Recordset 'Makes a new recordset
- '****************************************************************
- Dim DatabasePath As String 'Path of the database
- '****************************************************************
- Dim SRSQL As String 'This is language used to manipulate the data by making a new connection string
- '****************************************************************
- Dim SRLoc As String 'Location of database
- Dim ExitSystem As String 'Exits the program
- Dim Message As String
- Private Sub cmdBack_Click()
- '******************************************************************************************************
- 'Returns the user to their previous form
- '******************************************************************************************************
- Unload Me 'Stops the program instead of hiding the form
- MainMenu.Show 'Opens the Main Menu form
- End Sub
- '******************************************************************************************************************************************
- 'Login
- '******************************************************************************************************************************************
- Private Sub cmdLogin_Click()
- Dim SearchUsername As String
- Dim SearchPassword As String
- 'Verifies the Login with the Database
- SRLoc = App.Path & "\SandwichOrder.mdb" 'Location of Database
- StringConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & SRLoc
- SearchUsername = txtUsername.Text
- SearchPassword = txtPassword.Text
- SRSQL = "SELECT * FROM tblCustomerDetails WHERE Username = " & "'" & SearchUsername & "'" & " And Password = " & "'" & SearchPassword & "'" & ""
- 'Makes a SQL
- databaseconnection.ConnectionString = StringConnectionString
- databaseconnection.Open
- With rst
- .ActiveConnection = databaseconnection
- .LockType = adLockOptimistic
- .CursorType = adOpenKeyset
- .Open SRSQL
- 'Test for a valid user
- If .EOF Then
- 'Message Box to show incorrect username or password
- MsgBox "The Username or Password you have entered is incorrect", vbCritical
- Exit Sub
- End If
- End With
- Username = txtUsername.Text
- Unload Me 'Stops the program instead of hiding the form
- Order.Show 'Opens the order form
- Order.cmbBreadType.Text = "Please Select Bread Type"
- Order.cmbBreadSize.Text = "Please Select Bread Size"
- Order.cmbFilling.Text = "Please Select Filling"
- Order.cmbDrinks.Text = "Please Select Drink(s)"
- End Sub
- Private Sub txtPassword_LostFocus() 'Lost focus has to be set to make the password work
- txtPassword.Text = Replace(txtPassword.Text, " ", "")
- End Sub
- Private Sub cmdClose_Click()
- '******************************************************************************************************
- 'Closes project
- '******************************************************************************************************
- 'Message Box asking the user if they want to exit the system
- Message = MsgBox("Are you sure you want to exit?", vbYesNoCancel + vbCritical, "Exit")
- If Message = vbYes Then
- End
- End If
- End Sub
- '******************************************************************************************************************************************
- 'Format Password Textbox
- '******************************************************************************************************************************************
- Private Sub txtPassword_GotFocus()
- txtPassword.PasswordChar = "*"
- txtPassword.Text = ""
- End Sub
- '******************************************************************************************************************************************
- 'Format Username Textbox
- '******************************************************************************************************************************************
- Private Sub txtUsername_GotFocus()
- txtUsername.Text = ""
- End Sub
- Private Sub txtUsername_LostFocus() 'Lost focus has to be set to make the username work
- txtUsername.Text = Replace(txtUsername.Text, " ", "")
- End Sub
- Private Sub Form_Load()
- '******************************************************************************************************
- 'Loads form
- '******************************************************************************************************
- Me.Left = (Screen.Width - Me.Width) / 2 'Centres the form
- Me.Top = (Screen.Height - Me.Height) / 2 'Centres the form
- End Sub
- Private Sub Form_Unload(Cancel As Integer)
- '******************************************************************************************************
- 'Unloads Form
- '******************************************************************************************************
- rst.Close
- Set rst = Nothing
- databaseconnection.Close
- End Sub
Add Comment
Please, Sign In to add comment