Advertisement
Guest User

Untitled

a guest
Jan 16th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Compare Database
  2. Dim rsUser As Recordset
  3.  
  4. Private Sub CMDContact_Click()
  5. 'gives the user information to contact the booking system staff
  6. MsgBox ("Email Address: QinetiQ@yahoo.com" & vbCrLf & "Phonenumber: 0775839824" & vbCrLf & "Please only call during the hours of 8am to 8pm")
  7. End Sub
  8.  
  9. Private Sub CMDExit_Click()
  10. 'closes the form
  11. DoCmd.Close
  12. DoCmd.OpenForm ("frmOpen")
  13. End Sub
  14.  
  15. Private Function GenerateEmail()
  16. Dim AlphaChk As Integer
  17. Dim BaseNum  As Integer
  18. Dim i As Integer
  19. 'makes the new password for the specified user
  20. 'and changes it for the user
  21. rsUser.FindFirst "U_EmailAddress = '" & Me.emailaddress & "'"
  22.  
  23. Randomize Timer
  24.  
  25. rsUser.Edit
  26.  
  27. rsUser!U_Password = ""
  28. 'this makes a randomly genereated
  29. '5 character password
  30. For i = 1 To 5
  31.     AlphaChk = (Rnd() * 2) + 0.5
  32.    
  33.     If AlphaChk = 1 Then
  34.     BaseNum = (Rnd() * 26) + 95
  35.     rsUser!U_Password = rsUser!U_Password + Chr(BaseNum)
  36.    
  37.     ElseIf AlphaChk = 2 Then
  38.     BaseNum = (Rnd() * 9) + 0.5
  39.     rsUser!U_Password = rsUser!U_Password + Str(BaseNum)
  40.     End If
  41.    
  42. Next i
  43.  
  44. GenerateEmail = rsUser!U_Password
  45. rsUser!U_Password = Encrypt(rsUser!U_Password, 3)
  46. rsUser.Update
  47.  
  48. End Function
  49.  
  50. Private Sub cmdForgotPassword_Click()
  51. 'if the user forgets their password
  52. 'it asks for their email address
  53. MsgBox ("Please enter your email address")
  54.  
  55. Me.emailaddress.Visible = True
  56. cmdSendNewPassword.Visible = True
  57.  
  58.  
  59. End Sub
  60.  
  61. Private Sub cmdSendNewPassword_Click()
  62. 'if the users email address matches one in the table
  63. 'they send an email to that address with a new password
  64. rsUser.FindFirst "U_EmailAddress = '" & Me.emailaddress & "'"
  65.  
  66. If rsUser.NoMatch Then
  67.     MsgBox ("The Email Address does not exist, please type another in again")
  68.    
  69.     Else
  70.         GenerateEmail
  71.         'send Email
  72.        MsgBox ("an email has been send with a new password, please change your password when you login in the >Update< Account Section." & Decrypt(rsUser!U_Password, 3))
  73. End If
  74. End Sub
  75.  
  76. Private Sub sendEmail()
  77.  
  78. 'creates an instance of Outlook
  79. Set objOutlook = CreateObject("Outlook.application")
  80. Set objEmail = objOutlook.CreateItem(olMailItem)
  81.    
  82. rsUser.FindFirst "U_Username = '" & Me.username & "'"
  83.    
  84. 'creates and sends email
  85. With objEmail
  86.     .To = email
  87.     .Subject = U_username & "'s New Password "
  88.     .Body = "Here is your new password; " & U_Password & " please change your password when you login in the >Update< Account Section."
  89.     .Send
  90. End With
  91.                
  92. 'closes outlook
  93. Set objEmail = Nothing
  94. objOutlook.Quit
  95.  
  96. End Sub
  97.  
  98. Private Sub CMDHelpOff_Click()
  99. 'turns help off
  100. Me.username.SetFocus
  101. Me.Helplabel1.Visible = False
  102. Me.Helplabel2.Visible = False
  103. Me.Helplabel3.Visible = False
  104. Me.Helplabel4.Visible = False
  105. Me.PasswordLabel.Visible = True
  106. Me.Usernamelabel.Visible = True
  107. cmdhelpoff.Visible = False
  108. cmdhelpon.Visible = True
  109. End Sub
  110.  
  111. Private Sub CMDHelpOn_Click()
  112. 'turns help on
  113. Me.username.SetFocus
  114. Me.Helplabel1.Visible = True
  115. Me.Helplabel2.Visible = True
  116. Me.Helplabel3.Visible = True
  117. Me.Helplabel4.Visible = True
  118. Me.PasswordLabel.Visible = False
  119. Me.Usernamelabel.Visible = False
  120. cmdhelpon.Visible = False
  121. cmdhelpoff.Visible = True
  122. End Sub
  123.  
  124. Private Sub CMDLogin_Click()
  125.  
  126. rsUser.FindFirst "U_Username = '" & Me.username & "'"
  127. 'Searches for the entered Username
  128.  
  129. If rsUser.NoMatch = True Then
  130.     'if there are no matching usernames display this message
  131.    MsgBox "The Username you have entered does not exist", vbOKOnly, "Please Enter another Username" 'Displays this message when the wrong Username is entered
  132.    Me.username.SetFocus
  133.    
  134.     ElseIf rsUser!U_AccountLocked = True Or rsUser!U_AccountVerified = False Then
  135.     'if the user tries access their account and is locked or not verified it will display this message
  136.        MsgBox ("Your account is either locked or not verified, contact an admin for more info")
  137.         Me.username.SetFocus
  138.            
  139.             ElseIf rsUser!U_Admin = True And rsUser!U_Password = Encrypt(Me.password, 3) And U_AccountLocked = False Then
  140.             'If the password matches with the Username password and is an admin then
  141.                tempUserName = Me.username 'Takes the users username and uses it as the temp username
  142.                tempName = rsUser!U_Firstname 'Takes the users firstname and uses it as the temp firsname
  143.                tempID = rsUser!Staff_ID 'Takes the users staff id and uses it as the temp staff id
  144.                tempSurname = rsUser!U_Surname 'Takes the users surname and uses it as the temp surname
  145.                DoCmd.Close 'Closes form
  146.                DoCmd.OpenForm "frmAdminMainMenu" 'Opens Main Menu form
  147.                    
  148.                 ElseIf rsUser!U_Password = Encrypt(Me.password, 3) And rsUser!U_AccountLocked = False And rsUser!U_AccountVerified = True Then
  149.                 'If the password matches with the Username password and the account is not locked then
  150.                tempUserName = Me.username 'Takes the users username and uses it as the temp username
  151.                tempName = rsUser!U_Firstname 'Takes the users firstname and uses it as the temp firsname
  152.                tempID = rsUser!Staff_ID 'Takes the users staff id and uses it as the temp staff id
  153.                tempSurname = rsUser!U_Surname 'Takes the users surname and uses it as the temp surname
  154.                DoCmd.Close 'Closes form
  155.                DoCmd.OpenForm "frmMainMenu" 'Opens Main Menu form
  156.        
  157.                             Else
  158.                                 MsgBox "Wrong password and/or Username" 'Displays this message when the wrong password is entered
  159.                                Me.username.SetFocus
  160.                             End If
  161.  
  162. End Sub
  163.  
  164. Private Sub CMDRegister_Click()
  165. 'Closes the form and opens the new user form
  166. DoCmd.Close
  167. DoCmd.OpenForm ("frmNewUser")
  168. End Sub
  169.  
  170. Private Sub Form_load()
  171. 'When the form loads set tbl user as rsuser
  172. Set rsUser = CurrentDb.OpenRecordset("tbluser", dbOpenDynaset)
  173. 'make these labels, buttons and text boxes invisible on form load
  174. Me.PasswordLabel.Visible = False
  175. Me.Usernamelabel.Visible = False
  176. Me.emailaddress.Visible = False
  177. cmdSendNewPassword.Visible = False
  178. cmdhelpon.Visible = False
  179. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement