it is givving me bad filename errorCode:Dim tmp As Variant Dim Users As Integer Dim strLineValue As String Dim strValueToFind As String Sub CreateFileAndWrite() Users = FreeFile 'Open the document to write to. Look in the documentation 'at the Open statement for more information and different modes. Open "\\ict-server\stud_redir\davidmica\dtop\personal PR\Users.txt" For Output As Users 'Use the print or Write statement to add data to the file. 'Again, the documentation will give you more info. Print #Users, tmp 'Close the file. Close #Users End Sub Sub WriteInFile() Users = FreeFile 'Set the string you want to find in the file. strValueToFind = tmp Open "\\ict-server\stud_redir\davidmica\dtop\personal PR\Users.txt" For Input As Users 'Read each line until either the string has been 'found or you have reached the end of the file. Do Until EOF(Users) Line Input #Users, strLineValue If InStr(strLineValue, strValueToFind) > 0 Then MsgBox "User you Selected Already Exists, Sry" 'Close the file and exit this loop Close #Users Exit Do Else End If Loop Close #Users End Sub Private Sub cmdCheckUser_Click() Set Myfso = CreateObject("Scripting.FileSystemObject") tmp = txtUser.Text If (tmp = "") Then MsgBox "Please Enter A Username Before You Click Check, Thanks", , "No Username Found!" Else MsgBox "Please Wait... while checking your username availability", , "Please Wait" If (Myfso.FileExists("\\ict-server\stud_redir\davidmica\dtop\personal PR\Users.txt")) Then MsgBox "hello" Call WriteInFile Else Call CreateFileAndWrite End If End If End Sub




Reply With Quote