Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SaveAs problem.. 1

Status
Not open for further replies.

keeyean

MIS
Sep 29, 2001
32
0
0
US
Below are the codes of Save and SaveAs ...
but once i open a file(to input data in the program)... when i select SaveAs... a save dialog will pop up.. but when i select "cancel"... a error msg "Cancel was selected" will pop up... am i missing something in the code??



Public Sub mnuSave_Click()
'if the user has previously selected a file then save it
If Fil <> &quot;&quot; Then
Save
Else
'the user hasn't selected a file so make them select one
mnuSaveAs_Click
End If

End Sub

Public Sub mnuSaveAs_Click()
' the function to get the filename
Fil = GetFileName

'only let the user save if they selected a file
If Fil <> &quot;&quot; Then
Save
End If
End Sub

Public Function GetFileName() As String
With CommonDialog1
.FileName = &quot;&quot; 'Clear out the dialog box's filename
.DialogTitle = &quot;Save As&quot;
.ShowSave
End With

GetFileName = CommonDialog1.FileName
End Function
 
Hi,

if commondialog1.cancelerror is true (its not by default), the commondialog wil generate an error when the user clicks the cancel button:
----------------------------------------------------------
Private Function SaveFileAs(Path As String, FileName As String)
On Error GoTo ErrHndl:
ComDlg.DialogTitle = &quot;Save file as&quot;
ComDlg.CancelError = True
ComDlg.Flags = cdlOFNOverwritePrompt
ComDlg.InitDir = Path
ComDlg.FileName = FileName
ComDlg.Action = 2
SaveFileAs = ComDlg.FileName
Exit Function
ErrHndl: ' return a null string if the user cancels
If Err.Number = 32755 Then
SaveFileAs = &quot;&quot;
Else
MsgBox (Err.Description)
End If
end function
------------------------------------------------------------
Sunaj
 
The Cancel operation will be reported to your program by means of an error when you set the CancelError property of the Common Dialog to True. The specific error number will be 32755 (= cdlCancel).

Public Function GetFileName() As String
On Error Goto PROC_ERROR
With CommonDialog1
.FileName = vbNullString 'Clear out the dialog box's filename
.DialogTitle = &quot;Save As&quot;
.CancelError = True
.ShowSave
GetFileName = .FileName
End With

PROC_EXIT:
Exit Function

PROC_ERROR:
Select Case Err.Number = cdlCancel
Case True
Goto PROC_EXIT 'Operation Canceled, No FileName
Case False
'Process other error
MsgBox &quot;Other error while saving file &quot; & CommonDialog1.FileName
Goto PROC_EXIT
End Select

End Function

_________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top