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:
''Registry Option Key Backup Private Sub cmdBackup_Click() ' Check for empty textbox. If Text1.Text = "" Then Call MsgBox("You must enter a File Name! ", vbOKOnly + vbExclamation + vbApplicationModal + vbDefaultButton1, "BACKUP") Text1.SetFocus Exit Sub End If ' Check for existing file name Dim MsgResponse As VbMsgBoxResult If Err.Number <> 58 Then MsgResponse = MsgBox("That file name already exists!" & Chr(10) & Chr(13) & "Do You want to overwrite the file?", vbYesNo + vbExclamation, "Alert !") If MsgResponse = vbYes Then GoTo Name '<--------Tried GoTo in here but it just writes Key.REG and doesnt include the Name or date. Else If MsgResponse = vbNo Then Text1.SetFocus Exit Sub End If End If Name: Dim sDate As String sDate = Format$(Date, "mm-dd-yy") ' Here we go. Shell "regedit /e ./OptionKeyBackups/Keys.reg HKEY_LOCAL_MACHINE\Software\MyApp\IIP\Option" Name "./OptionKeyBackups/Keys.reg" As "./OptionKeyBackups/" & Text1.Text & "-" & sDate & ".REG" ' Then we Call MsgBox("The Option Key backup has been saved. ", vbOKOnly + vbInformation + vbApplicationModal + vbDefaultButton1, "FILE SAVE") End If End Sub
Can something simple like this be done to check if a file exists?




Reply With Quote