Bud Goss
bgoss711 at ameritech.net
Thu Mar 19 12:17:21 CDT 2009
My search for a solution in the hoary seas of Windows APIs and an additional question. I am mildly astonished at the number of posts my original question has generated. As an intermediate level developer APIs are a bit intimidating- I have never tried to use one of them before. For those other intermediate lurkers who may be following this string, I thought that the following may be useful: My original post (shown below) generated a response from Rocky Smolin. It assured me that what I wanted to do was ,in fact, possible. I got out my ADH and tried and with Rocky’s code tried to develop a solution. But the ADH can also be difficult for an intermediate level developer. I did a Google and found more explicit examples by Ken Getz in ( The Access WEB) that I was able to use. www.mvps.org/access/toc.htm Index item “Call the Standard Windows File Open/Save Dialog Box” However, even this was (for me) a bit dense. Then Stuart McLachlan posted his code (shown below) that is easier for me to follow . My additional question is: After I evoke the Dialog Box, if I click on “Save” without entering a file name the system does nothing. If I then click on “Cancel”, I can test for a zero length string, and display an error message or direct the application to a default file directory and .txt file name. I can live with I now have, But is there an easy way (using Stuart’s code) to have the system respond when I click on “Save” without entering a file name? Finally, thanks to those who responded to my post. >>> Stuart McLachlan’s post with code Using the Windows API 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 SaveFileName() as String Dim OpenFile As OPENFILENAME Dim lReturn As Long Dim sFilter As String OpenFile.lStructSize = Len(OpenFile) ‘OpenFile.hwndOwner = Me.hWnd ‘I had to modify this line (as shown below) to get the function to run OpenFile.hwndOwner = hWnd OpenFile.hInstance = 0 sFilter = "" & Chr(0) OpenFile.lpstrFilter = sFilter OpenFile.nFilterIndex = 1 OpenFile.lpstrFile = String(257, 0) OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1 OpenFile.lpstrFileTitle = OpenFile.lpstrFile OpenFile.nMaxFileTitle = OpenFile.nMaxFile OpenFile.lpstrInitialDir = "C:\" OpenFile.lpstrTitle = "Select File" OpenFile.flags = 0 lReturn = GetSaveFileName(OpenFile) SaveFilename = Left$(OpenFile.lpstrFile, InStr(OpenFile.lpstrFile, Chr$(0)) - 1) End Function > My Original Post -----Original Message----- > From: accessd-bounces at databaseadvisors.com > [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Bud Goss > Sent: Tuesday, March 17, 2009 2:45 PM > To: Access Group > Subject: [AccessD] Dialog Box for Creating .txt tables > > I have an Access application that creates a text (.txt) table using > DoCmd.TransferText. > > In this application, I would like to display a windows dialog box showing > “Save in;” and “File name:” that would allow the user to navigate to the > directory where the table would be located and designate file name to be > used. > (Similar to the dialog box that you see when you do a file save as in > Microsoft word etc.) > > Is it possible to do this in Access? > > If so, would some one tell me where I can find information and examples. > --