Guest User

Untitled

a guest
Aug 2nd, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Private Sub cmdBack_Click()
  2. '******************************************************************************************************
  3. 'Returns the user to their previous form
  4. '******************************************************************************************************
  5. Unload Me 'Stops the program instead of hiding the form
  6. MainMenu.Show 'Opens the Main Menu form
  7. End Sub
  8.  
  9. Private Sub CmdClearDetails_Click()
  10. '******************************************************************************************************
  11. 'Clears all information in the fields
  12. '******************************************************************************************************
  13. txtUsername.Text = ""
  14. txtPassword.Text = ""
  15. lstTitle.Text = ""
  16. txtFirstName.Text = ""
  17. txtSurname.Text = ""
  18. txtAddress.Text = ""
  19. txtPostcode.Text = ""
  20. txtHomeNo.Text = ""
  21. txtMobileNo.Text = ""
  22. txtEmailAddress.Text = ""
  23. lstGender.Text = ""
  24.  
  25. End Sub
  26.  
  27. Private Sub cmdClose_Click()
  28. '******************************************************************************************************
  29. 'Closes project
  30. '******************************************************************************************************
  31.  
  32. 'Message Box asking the user if they want to exit the system
  33. Message = MsgBox("Are you sure you want to exit?", vbYesNoCancel + vbCritical, "Exit")
  34. If Message = vbYes Then
  35. End
  36.  
  37. End If
  38.  
  39. End Sub
  40.  
  41. Private Sub cmdMakeUsername_Click()
  42. '******************************************************************************************************
  43. 'Creates a username
  44. '******************************************************************************************************
  45.  
  46. MakeUsername = Mid(txtFirstName.Text, 1, 2) & Mid(txtAddress.Text, 1, 2) & Mid(txtHomeNo.Text, 2, 4) & Mid(txtEmailAddress.Text, 1, 2)
  47.      txtUsername.Text = MakeUsername
  48.      'Message Box asking the user to create a password that doesn't relate to the username
  49. MsgBox ("Please type in a password which doesn't relate to the username")
  50.    
  51. End Sub
  52.        
  53. Private Sub CmdNext_Click()
  54. '******************************************************************************************************
  55. 'Takes the user to the Order form where they can order their meal
  56. '******************************************************************************************************
  57.  
  58. Username = txtUsername.Text
  59. Unload Me 'Stops the program instead of hiding the form
  60. Order.Show 'Opens the Order form
  61. Order.cmbBreadType.Text = "Please Select Bread Type"
  62. Order.cmbBreadSize.Text = "Please Select Bread Size"
  63. Order.cmbFilling.Text = "Please Select Filling"
  64. Order.cmbDrinks.Text = "Please Select Drink(s)"
  65.  
  66. End Sub
  67.  
  68. Private Sub CmdSaveDetails_Click()
  69. '******************************************************************************************************
  70. 'Saves the customer's details to the Recordset
  71. '******************************************************************************************************
  72.  
  73. 'Validation for when the fields are empty
  74.  
  75. If txtPassword = "" Then
  76. MsgBox ("Please type in a password which doesn't relate to the username.")
  77. End If
  78.  
  79. If lstTitle = "" Then
  80. MsgBox ("Please select your Title.")
  81. End If
  82.  
  83. If txtFirstName = "" Then
  84. MsgBox ("Please type in your First Name.")
  85. End If
  86.  
  87. If IsNumeric(txtFirstName.Text) Then
  88. MsgBox ("Please only type in letters in the First Name field.")
  89. End If
  90.  
  91. If txtSurname = "" Then
  92. MsgBox ("Please type in your Surname.")
  93. End If
  94.  
  95. If IsNumeric(txtSurname.Text) Then
  96. MsgBox ("Please only type in letters in the Surname field.")
  97. End If
  98.  
  99. If txtAddress = "" Then
  100. MsgBox ("Please type in your Address.")
  101. End If
  102.  
  103. If txtPostcode = "" Then
  104. MsgBox ("Please type your Postcode.")
  105. End If
  106.  
  107. If txtHomeNo = "" Then
  108. MsgBox ("Please type in your Home No.")
  109. End If
  110.  
  111. If Not IsNumeric(txtHomeNo.Text) Then
  112. MsgBox ("Please only type in numbers in the Home No. field.")
  113. End If
  114.  
  115. If txtMobileNo = "" Then
  116. MsgBox ("Please type in your Mobile No.")
  117. End If
  118.  
  119. If Not IsNumeric(txtMobileNo.Text) Then
  120. MsgBox ("Please only type in numbers in the Mobile No. field.")
  121. End If
  122.  
  123. If txtEmailAddress = "" Then
  124. MsgBox ("Please type in your Email Address.")
  125. End If
  126.  
  127. If lstGender = "" Then
  128. MsgBox ("Please select your Gender.")
  129. End If
  130.  
  131.  
  132. Dim Answer As String
  133. 'Message box asking the user if they remembered to take a note of their username
  134. Answer = MsgBox(Prompt:="Did you remember to take a note of your username?", Buttons:=vbYesNo)
  135. If Answer = vbNo Then
  136.     Exit Sub
  137.     End If
  138.  
  139. With rst
  140. rst.AddNew 'Adds a new blank line to the end of the Recordset
  141. .Fields("Username").Value = txtUsername.Text
  142. .Fields("Password").Value = txtPassword.Text
  143. .Fields("Title").Value = lstTitle.Text
  144. .Fields("First Name").Value = txtFirstName.Text
  145. .Fields("Surname").Value = txtSurname.Text
  146. .Fields("Address").Value = txtAddress.Text
  147. .Fields("Postcode").Value = txtPostcode.Text
  148. .Fields("HomeNo").Value = txtHomeNo.Text
  149. .Fields("MobileNo").Value = txtMobileNo.Text
  150. .Fields("EmailAdd").Value = txtEmailAddress.Text
  151. .Fields("Gender").Value = lstGender.Text
  152.  
  153. 'Adds the new data to the Recordset
  154. 'Message box confirming the customer's details have been successfully saved to the Database
  155. MsgBox "Details have been successfully saved."
  156. End With
  157. rst.Update
  158.  
  159. End Sub
  160.  
  161. Private Sub txtPassword_LostFocus() 'Lost focus has to be set to make the password work
  162. txtPassword.Text = Replace(txtPassword.Text, " ", "")
  163. End Sub
  164. '******************************************************************************************************************************************
  165. 'Format Password Textbox
  166. '******************************************************************************************************************************************
  167. Private Sub txtPassword_GotFocus()
  168. txtPassword.PasswordChar = "*"
  169. txtPassword.Text = ""
  170. End Sub
  171. '******************************************************************************************************************************************
  172. 'Format Username Textbox
  173. '******************************************************************************************************************************************
  174. Private Sub txtUsername_GotFocus()
  175. txtUsername.Text = ""
  176. End Sub
  177.  
  178. Private Sub txtUsername_LostFocus() 'Lost focus has to be set to make the username work
  179. txtUsername.Text = Replace(txtUsername.Text, " ", "")
  180. End Sub
  181.  
  182. Private Sub Form_Load()
  183. '******************************************************************************************************
  184. 'Loads form
  185. '******************************************************************************************************
  186.  
  187. 'Verifies the Login with the Database
  188.  
  189. SRLoc = App.Path & "\SandwichOrder.mdb" 'Location of Database
  190. databaseconnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & SRLoc
  191. databaseconnection.Open
  192.  
  193. 'Assemble the connection string as a string.
  194. SRSQL = "SELECT * FROM tblCustomerDetails"
  195. 'Sets the connection string property of the connection object to the string shown above
  196.  
  197.  
  198.  
  199. 'Checks to see if the username and password matches the one saved in the Database.
  200. With rst
  201. .ActiveConnection = databaseconnection
  202. .LockType = adLockOptimistic
  203. .CursorType = adOpenKeyset
  204. .Open SRSQL
  205. End With
  206.  
  207.  
  208. cmdSaveDetails.Enabled = False 'Disables command button
  209.  
  210. Me.Left = (Screen.Width - Me.Width) / 2 'Centres the form
  211. Me.Top = (Screen.Height - Me.Height) / 2 'Centres the form
  212.  
  213. End Sub
  214.  
  215. Private Sub lstGender_GotFocus()
  216. '******************************************************************************************************
  217. 'Loads content into ComboBox
  218. '******************************************************************************************************
  219. cmdSaveDetails.Enabled = True
  220. End Sub
  221.  
  222. Private Sub Form_Unload(Cancel As Integer)
  223. '******************************************************************************************************
  224. 'Unloads form
  225. '******************************************************************************************************
  226.  
  227.     rst.Close
  228.     Set rst = Nothing
  229.     databaseconnection.Close
  230.  
  231. End Sub
Add Comment
Please, Sign In to add comment