Earlier i had posted a question on re-naming a file when saved. I've since added an ErrorCheck for a blank TextBox. Now I would like to add an ErrorCheck to compare the name entered in the TextBox to files in the destination Dir. If the File name exists the user would be prompted to Overwrite Y/N. Y would overwrite w/ no further input. N would of course dump the user back to the form.

I've found a lot of "File Exists" code but none seem to compare a TextBox entry or they look for a specific file.

Right now, if the file exists I get a "Run-time error '58'. File exists". Clicking on Debug points to this line:

VB Code:
  1. Name "./OptionKeyBackups/OptionKeys.reg" As ./OptionKeyBackups/" & Text1.Text & ".REG"
(This was the answer to re-naming the file.)

How can I compare the name entered in the TextBox to files in the target Dir and do the Y/N Overwrite?

Here is the code in Form1 (I'm sorry if my coding skills make your eyes roll back in your head. :
VB Code:
  1. 'Registry Key Backup
  2. Private Sub cmdBackup_Click()
  3. 'This will export the registry info from (HKEY_LOCAL_MACHINE\Software\MyApp\IIP\Option)
  4. 'to the app.path
  5.  
  6. ' Check for blank textbox.
  7. If ErrorCheck() = 1 Then ' ErrorCheck is in "Module1"
  8. Exit Sub
  9. End If
  10. ' Here we go.
  11. Shell "regedit /e ./OptionKeyBackups/OptionKeys.reg HKEY_LOCAL_MACHINE\Software\MyApp\IIP\Option"
  12. Name "./OptionKeyBackups/OptionKeys.reg" As "./OptionKeyBackups/" & Text1.Text & ".REG"
  13.  
  14. Call MsgBox("The Option Key backup has been saved as " & Text1.Text & ".REG", vbOKOnly + vbInformation + vbApplicationModal + vbDefaultButton1, "FILE SAVE")
  15.  
  16. End Sub
Code in Modue1 for the blank TextBox:
VB Code:
  1. Public Function ErrorCheck() As Integer
  2.  
  3. Dim IntPress As Single
  4.  
  5. ' Error Checking for blank TextBox from Form1.
  6. If (Form1.Text1.Text) = "" Then
  7. IntPress = MsgBox("You must enter a file name!    ", vbOKOnly + vbExclamation + vbDefaultButton1, "FILE SAVE")
  8. Form1.Text1.SetFocus
  9. ErrorCheck = 1
  10. Exit Function
  11. End If
  12.  
  13. End Function

Thanks for all the help.