Allow for user pressing cancel in File/Save API

Allow for user pressing cancel in File/Save API

Post by UGhpbCBUcn » Sat, 02 Aug 2008 01:32:02


I am using Access 2003 on Windows XP.

I am currently using the Windows File Open/Save Dialog box API to let a user
select where to save an excel file. It works great, but I would like to
inlcude code to allow for a user to cancel the save and return to the form
without anything happening. I have tried a couple different things but
can't get the desired actions to take place. I copied the code from mvps.org
for the API and am using the following code in the application.

Private Sub cmdExport_Click()
Dim strSaveFilename As String
Dim strRptName As String
Dim strFilter As String

strQryName = "qryDynamicExcess"

'Ask for SaveFileName
strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xls)", "*.xls")
strSaveFilename = ahtCommonFileOpenSave( _
OpenFile:=False, _
Filter:=strFilter, _
Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY)

strOutputFilename = strSaveFilename
DoCmd.OpenForm "frmPleaseWait"
DoCmd.TransferSpreadsheet acExport, , strQryName, strOutputFilename, True

Call FormatExcel
'If Right(strRptOutputLocation, 1) <> "\" Then
' strRptOutputLocation = strRptOutputLocation + "\"
'End If

DoCmd.Close acForm, "frmPleaseWait"

Where would I put the code to allow for a cancel?

Thanks in advance for your help.
 
 
 

Allow for user pressing cancel in File/Save API

Post by UGhpbCBUcn » Sat, 02 Aug 2008 01:41:06

Nevermind, I figured it out by looking at another post here:

http://www.yqcomputer.com/ +for+cancel&dg=microsoft.public.access.externaldata&cat=en_US_c6cc8422-101a-43ce-9880-3830ee9da43a&lang=en&cr=US&pt=&catlist=&dglist=&ptlist=&exp=&sloc=en-us

I added this to my code and it worked perfectly:

If strSaveFilename = "" Then 'User clicked cancel
Exit Sub

Thanks anyway!