|
-
Nov 27th, 2006, 11:49 AM
#1
Thread Starter
Lively Member
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:
''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?
-
Nov 27th, 2006, 09:09 PM
#2
Thread Starter
Lively Member
Re: Another question - Compare TextBox entry to see if file exists
Fixed it!!
VB Code:
'Check for existing file name
Dim MsgResponse As VbMsgBoxResult
If Dir$("./OptionKeyBackups/" & Text1.Text & "-" & sDate & ".REG") <> "" Then
MsgResponse = MsgBox("That file name already exists!" & vbCrLf & _
"Do You want to overwrite the file?", vbYesNo + vbExclamation, "Alert !")
If MsgResponse = vbYes Then
Kill "./OptionKeyBackups/" & Text1.Text & "-" & sDate & ".REG"
Else
If MsgResponse = vbNo Then
Text1.SetFocus
Exit Sub
End If
End If
End If
'Backing up
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 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|