[AccessD] Use of Application.FileDialog(msoFileDialogSaveAs) inAccess 2007 - THANKS!

Brad Marks BradM at blackforestltd.com
Sat Jan 22 18:44:23 CST 2011


Stuart,

Thanks for the help, I appreciate it.

I now have two approaches that both work.  I am planning to use the code that you posted.  

I think that it is always beneficial to have "extra tricks in the bag" for possible future use.

Sincerely,
Brad  

-----Original Message-----
From: accessd-bounces at databaseadvisors.com on behalf of Stuart McLachlan
Sent: Fri 1/21/2011 1:22 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Use of Application.FileDialog(msoFileDialogSaveAs) inAccess 2007
 
Use theGetSaveFileName API.  

Paste the following into a module and then use GetSaveFile()  in your exporting function.


Code:

Declare Function GetSaveFileName Lib "comdlg32.dll" Alias _
         "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
   
Type OPENFILENAME
  lStructSize As Long
  hwndOwner As Long
  hInstance As Long
  lpstrFilter As String
  lpstrCustomFilter As String
  nMaxCustFilter As Long
  nFilterIndex As Long
  lpstrFile As String
  nMaxFile As Long
  lpstrFileTitle As String
  nMaxFileTitle As Long
  lpstrInitialDir As String
  lpstrTitle As String
  flags As Long
  nFileOffset As Integer
  nFileExtension As Integer
  lpstrDefExt As String
  lCustData As Long
  lpfnHook As Long
  lpTemplateName As String
End Type

Function GetSaveFile(Directory As String) As String
         Dim OpenFile As OPENFILENAME
         Dim lReturn As Long
         Dim sFilter As String
         OpenFile.lStructSize = Len(OpenFile)
         OpenFile.hwndOwner = 0
         OpenFile.hInstance = 0
         sFilter = "" & Chr(0)
         OpenFile.lpstrFilter = sFilter
         OpenFile.nFilterIndex = 0
         OpenFile.lpstrFile = String(257, 0)
         OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
         OpenFile.lpstrFileTitle = OpenFile.lpstrFile
         OpenFile.nMaxFileTitle = OpenFile.nMaxFile
         OpenFile.lpstrInitialDir = Directory
         OpenFile.lpstrTitle = "Select File"
         OpenFile.flags = 0
         lReturn = GetOpenFileName(OpenFile)
         GetSaveFile = Left$(OpenFile.lpstrFile, InStr(OpenFile.lpstrFile, Chr$(0)) - 1)
End Function




On 21 Jan 2011 at 9:55, Brad Marks wrote:

> All,
> 
> I have just started to experiment with
> Application.FileDialog(msoFileDialogSaveAs).
> 
> We have an Access 2007 application that uses
> "DoCmd.TransferSpreadsheet" to generate several Excel files from
> Access Queries.  Currently this application has the name of the Excel
> file "hard coded" in the application.
> 
> I would like to give our end-users the option of changing the name of
> the Excel file (and folder name) when the file is generated. 
> 
> Using  Application.FileDialog(msoFileDialogSaveAs) seems to work
> nicely, but I am a bit concerned that this may not be a good long-term
> approach.
> 
> When doing research about this method, I stumbled upon this statement
> on a Microsoft web page.
> 
> " msoFileDialogSaveAs constants are not supported in Microsoft Office
> Access 2007"
> 
> This, and other comments that I have read have made me wonder if I am
> heading down the wrong path. (no pun intended) 
> 
> Is Application.FileDialog(msoFileDialogSaveAs) a viable approach?
> 
> Is there a better way to give the end-users an easy way to change the
> name (and folder) of the generated Excel file?
> 
> Thanks,
> Brad
> 




-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




More information about the AccessD mailing list