Results 1 to 5 of 5

Thread: [RESOLVED] Another question - Compare TextBox entry to see if file exists

Hybrid View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Location
    Ft. Worth, Texas
    Posts
    67

    Re: Another question - Compare TextBox entry to see if file exists

    Anyone?

    I simplified things a bit by removing Module1 and using this to check for an empty TextBox. The part I'm still having problems with is checking for an existing file name. It traps the initial Error 58. If "No" is clicked it puts focus back to Text1. Clicking "Yes" gives a file name of "Keys.REG" and then throws Error 58 again. Adding the current date to the name minimizes the chance but i don't want an error thrown. Thanks in advance for the help! New to all this but learning!

    VB Code:
    1. ''Registry Option Key Backup
    2. Private Sub cmdBackup_Click()
    3.    
    4. ' Check for empty textbox.
    5. If Text1.Text = "" Then
    6. Call MsgBox("You must enter a File Name!   ", vbOKOnly + vbExclamation + vbApplicationModal + vbDefaultButton1, "BACKUP")
    7. Text1.SetFocus
    8. Exit Sub
    9. End If
    10.  
    11. ' Check for existing file name
    12. Dim MsgResponse As VbMsgBoxResult
    13. If Err.Number <> 58 Then
    14.  
    15.     MsgResponse = MsgBox("That file name already exists!" & Chr(10) & Chr(13) & "Do You want to overwrite the file?", vbYesNo + vbExclamation, "Alert !")
    16.     If MsgResponse = vbYes Then
    17.       GoTo Name             '<--------Tried GoTo in here but it just writes Key.REG and doesnt include the Name or date.
    18.     Else
    19.     If MsgResponse = vbNo Then
    20. Text1.SetFocus
    21. Exit Sub
    22. End If
    23.     End If
    24.  
    25. Name:
    26. Dim sDate As String
    27.     sDate = Format$(Date, "mm-dd-yy")
    28.      
    29. ' Here we go.
    30.  
    31. Shell "regedit /e ./OptionKeyBackups/Keys.reg HKEY_LOCAL_MACHINE\Software\MyApp\IIP\Option"
    32. Name "./OptionKeyBackups/Keys.reg" As "./OptionKeyBackups/" & Text1.Text & "-" & sDate & ".REG"
    33.  
    34. ' Then we
    35. Call MsgBox("The Option Key backup has been saved.   ", vbOKOnly + vbInformation + vbApplicationModal + vbDefaultButton1, "FILE SAVE")
    36. End If
    37. End Sub

    Can something simple like this be done to check if a file exists?

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Location
    Ft. Worth, Texas
    Posts
    67

    Re: Another question - Compare TextBox entry to see if file exists

    Fixed it!!

    VB Code:
    1. 'Check for existing file name
    2.    Dim MsgResponse As VbMsgBoxResult
    3.  
    4.    If Dir$("./OptionKeyBackups/" & Text1.Text & "-" & sDate & ".REG") <> "" Then
    5.       MsgResponse = MsgBox("That file name already exists!" & vbCrLf & _
    6.                    "Do You want to overwrite the file?", vbYesNo + vbExclamation, "Alert !")
    7.       If MsgResponse = vbYes Then
    8.          Kill "./OptionKeyBackups/" & Text1.Text & "-" & sDate & ".REG"
    9.  
    10.       Else
    11.       If MsgResponse = vbNo Then
    12.          Text1.SetFocus
    13.          Exit Sub
    14.          
    15.       End If
    16.    End If
    17. End If
    18.    
    19.    'Backing up
    20.    Shell ("regedit /e ./OptionKeyBackups/Keys.reg HKEY_LOCAL_MACHINE\Software\MyApp\IIP\Option")
    21.  
    22.    Name "./OptionKeyBackups/Keys.reg" As "./OptionKeyBackups/" & Text1.Text & "-" & sDate & ".REG"
    23.  
    24.    ' Then we
    25.    Call MsgBox("The Option Key backup has been saved.", vbOKOnly + vbInformation + vbApplicationModal + vbDefaultButton1, "FILE SAVE")
    26.  
    27. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width