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:
(This was the answer to re-naming the file.)VB Code:
Name "./OptionKeyBackups/OptionKeys.reg" As ./OptionKeyBackups/" & Text1.Text & ".REG"
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.:
Code in Modue1 for the blank TextBox:VB Code:
'Registry Key Backup Private Sub cmdBackup_Click() 'This will export the registry info from (HKEY_LOCAL_MACHINE\Software\MyApp\IIP\Option) 'to the app.path ' Check for blank textbox. If ErrorCheck() = 1 Then ' ErrorCheck is in "Module1" Exit Sub End If ' Here we go. Shell "regedit /e ./OptionKeyBackups/OptionKeys.reg HKEY_LOCAL_MACHINE\Software\MyApp\IIP\Option" Name "./OptionKeyBackups/OptionKeys.reg" As "./OptionKeyBackups/" & Text1.Text & ".REG" Call MsgBox("The Option Key backup has been saved as " & Text1.Text & ".REG", vbOKOnly + vbInformation + vbApplicationModal + vbDefaultButton1, "FILE SAVE") End Sub
VB Code:
Public Function ErrorCheck() As Integer Dim IntPress As Single ' Error Checking for blank TextBox from Form1. If (Form1.Text1.Text) = "" Then IntPress = MsgBox("You must enter a file name! ", vbOKOnly + vbExclamation + vbDefaultButton1, "FILE SAVE") Form1.Text1.SetFocus ErrorCheck = 1 Exit Function End If End Function
Thanks for all the help.




:
Reply With Quote