Richard,
I'm sure there are some newer ways to do this, but I do have a solution for you to start with. What you are referring to are called Common Dialog forms (save, save as, open, fonts, etc).
I use the Open common dialog quite extensively for many of my own applications. You can use the common dialog control from both MS-
VB and MS-Access, but there are some subtle differences. I do use a time-proven method in MS-Access applications that does not actually rely on the common dialog controls themselves.
You need a couple of things to run this - first of all, you need to declare the type and called function like this:
Type adh_accOfficeGetFileNameInfo
hWndOwner As Long
strAppName As String * 255
strDlgTitle As String * 255
strOpenTitle As String * 255
strFile As String * 4096
strInitialDir As String * 255
strFilter As String * 255
lngFilterIndex As Long
lngView As Long
lngFlags As Long
End Type
Declare Function adh_accOfficeGetFileName Lib "msaccess.exe" _
Alias "#56" (gfni As adh_accOfficeGetFileNameInfo, ByVal fOpen As Integer) As Long
I usually put these declares, etc into their own module for reusability, especially if I want to call them from multiple locations within the application. I myself keep these declares in a module named basDeclares.
Inside your code-behind-forms or module (depending on where you want to call this from), put the following into the Declares section:
Dim gfni As adh_accOfficeGetFileNameInfo
To call the Open common dialog form, you can do something like the
following:
With gfni
.hWndOwner = Application.hWndAccessApp
.strAppName = "Select the filename to process"
.strDlgTitle = "Select the filename to process"
.strOpenTitle = "Select"
.strFile = ""
.strInitialDir = "C:\My Documents"
.strFilter = "All Files (*.*)"
.lngFilterIndex = 0
.lngView = adhcGfniViewList
.lngFlags = adhcGfniNoChangeDir Or adhcGfniInitializeView
End With
If adhOfficeGetFileName(gfni, True) = adhcAccErrSuccess Then
strPathAndFileName = Trim(gfni.strFile)
End If
In this case, strPathAndFileName will contain the actual drive, path, and filename of the file that was selected by the user using the Open common dialog. If I remember correctly, if the user clicks the [Cancel] button, strPathAndFileName will contain a zero-length string.
As I was saying, there are other common dialog forms (save, save as, etc) that can also be invoked - there are also common dialog controls in both Access and
VB which can also be used. If you'd like, I can also look up the other adh functions for the other common dialogs.
Hope this helps.
Warren
:D