Ginger16
asked on
overwrite existing file
How can I set the default filename in the save dialog box to a varible name, such as strTitle, and ask to overwrite if the file already exists. Her is the code.
Private Sub cmdSave_Click()
'Declare variable
Dim strFilename As String
'Do the error handler
cdbOpenSave.CancelError = True
On Error GoTo ErrHandler
'Set the properties of the text control
cdbOpenSave.Filter = _
"Text Files|*.txt*"
'Show the save-as dialog box
cdbOpenSave.ShowSave
'retrieve the filename
strFilename = cdbOpenSave.FileName & ".txt"
'save the file
Open strFilename For Output As #1
Print #1, Text1
Close #1
Exit Sub
ErrHandler:
End
Private Sub cmdSave_Click()
'Declare variable
Dim strFilename As String
'Do the error handler
cdbOpenSave.CancelError = True
On Error GoTo ErrHandler
'Set the properties of the text control
cdbOpenSave.Filter = _
"Text Files|*.txt*"
'Show the save-as dialog box
cdbOpenSave.ShowSave
'retrieve the filename
strFilename = cdbOpenSave.FileName & ".txt"
'save the file
Open strFilename For Output As #1
Print #1, Text1
Close #1
Exit Sub
ErrHandler:
End
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Answered perfectly. Thanks.
just assign a string with file name to a property FileName.
Dim sFile as string
Dim strFilename As String
'Do the error handler
cdbOpenSave.CancelError = True
On Error GoTo ErrHandler
'Set the properties of the text control
cdbOpenSave.Filter = _
"Text Files|*.txt*"
sFile = "SomeFile"
cdb.FileName = sFile
'Show the save-as dialog box
cdbOpenSave.ShowSave
'retrieve the filename
strFilename = cdbOpenSave.FileName & ".txt"
'save the file
Open strFilename For Output As #1
Print #1, Text1
Close #1
Exit Sub
ErrHandler