home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1995 August / pcpro-0895.iso / code / vb / vb10-5.txt < prev    next >
Encoding:
Text File  |  1995-06-10  |  1.6 KB  |  63 lines

  1. Sub cmdCancel_Click ()
  2. Unload Me
  3. End Sub
  4.  
  5. Sub cmdOK_Click ()
  6. Dim Title As String
  7. Dim Msg As String
  8. Dim DgDef, Response
  9. Dim Db As database, Ds As Dynaset, Ds2 As Dynaset
  10.  
  11. If txtUserName = "" Then
  12.     MsgBox "Enter a name to delete.", 32
  13.     Exit Sub
  14. End If
  15.  
  16. NewUser = txtUserName
  17.  
  18. Set Db = OpenDatabase("e:\vbpass\protect.mdb")
  19. Set Ds = Db.CreateDynaset("SELECT * FROM mtUserInfo WHERE mtUserInfo.CanDelete = True and UserName like '" & txtUserName & "';")      æall one line
  20. Set Ds2 = Db.CreateDynaset("SELECT * FROM mtUserInfo")
  21.  
  22. Ds2.MoveLast
  23. Ds2.MoveFirst
  24.  
  25. If Ds.RecordCount = 0 Then
  26.     MsgBox "Cannot locate that user name for deletion!", 16
  27.     Ds.Close
  28.     Ds2.Close
  29.     Db.Close
  30.     Exit Sub
  31. ElseIf Ds2.RecordCount <= 1 Then
  32.     Title = App.Title
  33.     Msg = "WARNING! If you delete all users, you will not be able to sign in next time you run this application. Make sure that you always have at least one user, if you have Password Protection enabled. Click on the Cancel button to stop deletion, or the OK button to proceed with deletion."     æall one line
  34.     DgDef = MB_OKCANCEL + MB_ICONSTOP + MB_DEFBUTTON2
  35.     Response = MsgBox(Msg, DgDef, Title)
  36.     If Response = IDOK Then
  37.         Ds.Delete
  38.         MsgBox "User Deleted.", 48
  39.         Ds.Close
  40.         Ds2.Close
  41.         Db.Close
  42.         Unload Me
  43.         Exit Sub
  44.     Else
  45.         Ds.Close
  46.         Ds2.Close
  47.         Db.Close
  48.         Unload Me
  49.         Exit Sub
  50.     End If
  51. Else
  52.     Ds.Delete
  53.     MsgBox "User Deleted.", 48
  54.     Ds.Close
  55.     Ds2.Close
  56.     Db.Close
  57.     Unload Me
  58.     Exit Sub
  59. End If
  60. End Sub
  61.  
  62.  
  63.