The problem is you're opening the users file for Output, this Automatically creates a New file, removing all your Users.
Instead of updating the File on every delete and keeping the file in a Textbox,
Why don't you just update the file when the user closes the form.
That way you can skip the entire DelUser Sub Routine and You won't need to keep the file in a Textbox, eg.
N.B. If you don't want a User to Type into a Combo, set the Style Property to DropDown List..Code:Option Explicit Private Sub cmdDel_Click() Dim I As Integer Dim sPass As String If cboUser.ListIndex < 0 Then Exit Sub 'No Users If Len(txtPass) = 0 Then 'make sure there is a password MsgBox "Please enter your password.", , "Error" Exit Sub End If For I = 1 To 20 'check to see if the user has to remain If Cn.mnuMsg(I).Caption = cboUser Then MsgBox "You can't delete this user until all there Msg's have been viewed", , "Error" Exit For End If Next If I < 21 Then Exit Sub 'get the user pass from the reg (eww_ secure Not) sPass = GetSetting(AppTitle, "Users", cboUser) 'compare the pWords If sPass = txtPass Then cboUser.RemoveItem cboUser.ListIndex DeleteSetting AppTitle, "Users", cboUser.Text MsgBox "User Removed", vbInformation + vbOKOnly, "User Removed" Else MsgBox "Please re-enter your password", , "Invalid Password" End If End Sub Private Sub Form_Load() 'Load the User File Dim iFile As Integer Dim sUserList As String iFile = FreeFile Open App.Path & "\Users.zan" For Input As iFile sUserList = Input(LOF(iFile), iFile) Close iFile While InStr(sUserList, vbCrLf) cboUser.AddItem Left(sUserList, InStr(sUserList, vbCrLf) - 1) sUserList = Mid$(sUserList, InStr(sUserList, vbCrLf) + 2) Wend If Len(sUserList) Then cboUser.AddItem sUserList If cboUser.ListCount Then cboUser.ListIndex = 0 txtPass.PasswordChar = "*" End Sub Private Sub Form_Unload(Cancel As Integer) 'Update the User File Dim iFile As Integer Dim iIndex As Integer iFile = FreeFile Open App.Path & "\Users.zan" For Output As iFile For iIndex = 0 To cboUser.ListCount - 1 Print #iFile, cboUser.List(iIndex) Next Close iFile End Sub Private Sub cmdCancel_Click() Unload Me End Sub
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]




Reply With Quote