I'm using the following code from the Access Web to open a folder. The
folder opens in "List" View. Is there an addition that I can make to
the code to force the folder to open in "Details" view?
'This code was originally written by Ken Getz.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
' Code courtesy of:
' Microsoft Access 95 How-To
' Ken Getz and Paul Litwin
' Waite Group Press, 1996
Type tagOPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
strFilter As String
strCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
strFile As String
nMaxFile As Long
strFileTitle As String
nMaxFileTitle As Long
strInitialDir As String
strTitle As String
Flags As Long
nFileOffset As Integer
nFileExtension As Integer
strDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Declare Function aht_apiGetOpenF ileName Lib "comdlg32.d ll" _
Alias "GetOpenFileNam eA" (OFN As tagOPENFILENAME ) As Boolean
Declare Function aht_apiGetSaveF ileName Lib "comdlg32.d ll" _
Alias "GetSaveFileNam eA" (OFN As tagOPENFILENAME ) As Boolean
Declare Function CommDlgExtended Error Lib "comdlg32.d ll" () As Long
Global Const ahtOFN_READONLY = &H1
Global Const ahtOFN_OVERWRIT EPROMPT = &H2
Global Const ahtOFN_HIDEREAD ONLY = &H4
Global Const ahtOFN_NOCHANGE DIR = &H8
Global Const ahtOFN_SHOWHELP = &H10
' You won't use these.
'Global Const ahtOFN_ENABLEHO OK = &H20
'Global Const ahtOFN_ENABLETE MPLATE = &H40
'Global Const ahtOFN_ENABLETE MPLATEHANDLE = &H80
Global Const ahtOFN_NOVALIDA TE = &H100
Global Const ahtOFN_ALLOWMUL TISELECT = &H200
Global Const ahtOFN_EXTENSIO NDIFFERENT = &H400
Global Const ahtOFN_PATHMUST EXIST = &H800
Global Const ahtOFN_FILEMUST EXIST = &H1000
Global Const ahtOFN_CREATEPR OMPT = &H2000
Global Const ahtOFN_SHAREAWA RE = &H4000
Global Const ahtOFN_NOREADON LYRETURN = &H8000
Global Const ahtOFN_NOTESTFI LECREATE = &H10000
Global Const ahtOFN_NONETWOR KBUTTON = &H20000
Global Const ahtOFN_NOLONGNA MES = &H40000
' New for Windows 95
Global Const ahtOFN_EXPLORER = &H80000
Global Const ahtOFN_NODEREFE RENCELINKS = &H100000
Global Const ahtOFN_LONGNAME S = &H200000
Function TestIt()
Dim strFilter As String
Dim lngFlags As Long
strFilter = ahtAddFilterIte m(strFilter, "Access Files (*.mda,
*.mdb)", _
"*.MDA;*.MD B")
strFilter = ahtAddFilterIte m(strFilter, "dBASE Files (*.dbf)",
"*.DBF")
strFilter = ahtAddFilterIte m(strFilter, "Text Files (*.txt)",
"*.TXT")
strFilter = ahtAddFilterIte m(strFilter, "All Files (*.*)", "*.*")
MsgBox "You selected: " & ahtCommonFileOp enSave(InitialD ir:="C:\",
_
Filter:=strFilt er, FilterIndex:=3, Flags:=lngFlags , _
DialogTitle:="H ello! Open Me!")
' Since you passed in a variable for lngFlags,
' the function places the output flags value in the variable.
Debug.Print Hex(lngFlags)
End Function
Function GetOpenFile(Opt ional varDirectory As Variant, _
Optional varTitleForDial og As Variant) As Variant
' Here's an example that gets an Access database name.
Dim strFilter As String
Dim lngFlags As Long
Dim varFileName As Variant
' Specify that the chosen file must already exist,
' don't change directories when you're done
' Also, don't bother displaying
' the read-only box. It'll only confuse people.
lngFlags = ahtOFN_FILEMUST EXIST Or _
ahtOFN_HIDEREAD ONLY Or ahtOFN_NOCHANGE DIR
If IsMissing(varDi rectory) Then
varDirectory = ""
End If
If IsMissing(varTi tleForDialog) Then
varTitleForDial og = ""
End If
' Define the filter string and allocate space in the "c"
' string Duplicate this line with changes as necessary for
' more file templates.
strFilter = ahtAddFilterIte m(strFilter, _
"Access (*.mdb)", "*.MDB;*.MD A")
' Now actually call to get the file name.
varFileName = ahtCommonFileOp enSave( _
OpenFile:=True, _
InitialDir:=var Directory, _
Filter:=strFilt er, _
Flags:=lngFlags , _
DialogTitle:=va rTitleForDialog )
If Not IsNull(varFileN ame) Then
varFileName = TrimNull(varFil eName)
End If
GetOpenFile = varFileName
End Function
Function ahtCommonFileOp enSave( _
Optional ByRef Flags As Variant, _
Optional ByVal InitialDir As Variant, _
Optional ByVal Filter As Variant, _
Optional ByVal FilterIndex As Variant, _
Optional ByVal DefaultExt As Variant, _
Optional ByVal FileName As Variant, _
Optional ByVal DialogTitle As Variant, _
Optional ByVal hwnd As Variant, _
Optional ByVal OpenFile As Variant) As Variant
' This is the entry point you'll use to call the common
' file open/save dialog. The parameters are listed
' below, and all are optional.
'
' In:
' Flags: one or more of the ahtOFN_* constants, OR'd together.
' InitialDir: the directory in which to first look
' Filter: a set of file filters, set up by calling
' AddFilterItem. See examples.
' FilterIndex: 1-based integer indicating which filter
' set to use, by default (1 if unspecified)
' DefaultExt: Extension to use if the user doesn't enter one.
' Only useful on file saves.
' FileName: Default value for the file name text box.
' DialogTitle: Title for the dialog.
' hWnd: parent window handle
' OpenFile: Boolean(True=Op en File/False=Save As)
' Out:
' Return Value: Either Null or the selected filename
Dim OFN As tagOPENFILENAME
Dim strFileName As String
Dim strFileTitle As String
Dim fResult As Boolean
' Give the dialog a caption title.
If IsMissing(Initi alDir) Then InitialDir = CurDir
If IsMissing(Filte r) Then Filter = ""
If IsMissing(Filte rIndex) Then FilterIndex = 1
If IsMissing(Flags ) Then Flags = 0&
If IsMissing(Defau ltExt) Then DefaultExt = ""
If IsMissing(FileN ame) Then FileName = ""
If IsMissing(Dialo gTitle) Then DialogTitle = ""
If IsMissing(hwnd) Then hwnd = Application.hWn dAccessApp
If IsMissing(OpenF ile) Then OpenFile = True
' Allocate string space for the returned strings.
strFileName = Left(FileName & String(256, 0), 256)
strFileTitle = String(256, 0)
' Set up the data structure before you call the function
With OFN
..lStructSize = Len(OFN)
..hwndOwner = hwnd
..strFilter = Filter
..nFilterIndex = FilterIndex
..strFile = strFileName
..nMaxFile = Len(strFileName )
..strFileTitle = strFileTitle
..nMaxFileTitle = Len(strFileTitl e)
..strTitle = DialogTitle
..Flags = Flags
..strDefExt = DefaultExt
..strInitialDir = InitialDir
' Didn't think most people would want to deal with
' these options.
..hInstance = 0
'.strCustomFilt er = ""
'.nMaxCustFilte r = 0
..lpfnHook = 0
'New for NT 4.0
..strCustomFilt er = String(255, 0)
..nMaxCustFilte r = 255
End With
' This will pass the desired data structure to the
' Windows API, which will in turn it uses to display
' the Open/Save As Dialog.
If OpenFile Then
fResult = aht_apiGetOpenF ileName(OFN)
Else
fResult = aht_apiGetSaveF ileName(OFN)
End If
' The function call filled in the strFileTitle member
' of the structure. You'll have to write special code
' to retrieve that if you're interested.
If fResult Then
' You might care to check the Flags member of the
' structure to get information about the chosen file.
' In this example, if you bothered to pass in a
' value for Flags, we'll fill it in with the outgoing
' Flags value.
If Not IsMissing(Flags ) Then Flags = OFN.Flags
ahtCommonFileOp enSave = TrimNull(OFN.st rFile)
Else
ahtCommonFileOp enSave = vbNullString
End If
End Function
Function ahtAddFilterIte m(strFilter As String, _
strDescription As String, Optional varItem As Variant) As String
' Tack a new chunk onto the file filter.
' That is, take the old value, stick onto it the description,
' (like "Databases" ), a null character, the skeleton
' (like "*.mdb;*.md a") and a final null character.
If IsMissing(varIt em) Then varItem = "*.*"
ahtAddFilterIte m = strFilter & _
strDescription & vbNullChar & _
varItem & vbNullChar
End Function
Private Function TrimNull(ByVal strItem As String) As String
Dim intPos As Integer
intPos = InStr(strItem, vbNullChar)
If intPos > 0 Then
TrimNull = Left(strItem, intPos - 1)
Else
TrimNull = strItem
End If
End Function