Option Compare Database
Option Explicit
' from http://vbnet.mvps.org/index.html?code/browse/browsenetwork.htm
'Add an editbox to the dialog: SHELL 5.0 or later only!
Private Const BIF_EDITBOX As Long = &H10
'insist on valid result (or CANCEL)
Private Const BIF_VALIDATE As Long = &H20
'Use the new dialog layout with the ability
'to resize: SHELL 5.0 or later only!
Private Const BIF_NEWDIALOGSTYLE As Long = &H40
Private Const BIF_USENEWUI As Long = (BIF_NEWDIALOGSTYLE Or BIF_EDITBOX)
Public Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Const OFN_CREATEPROMPT As Long = &H2000
Private 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
' abstracted so that you can call from no form
Public Function LaunchCdWithOwner(Optional strTitle As String = "Select a File", Optional ByRef strStartDir As String = "C:\") As String
Dim OpenFile As OPENFILENAME
Dim sFilter As String
Dim lReturn As Long
OpenFile.lStructSize = Len(OpenFile)
OpenFile.HwndOwner = 0
sFilter = "All Files (*.*)" & Chr(0) & "*.*" & Chr(0) & _
"Word File (*.doc)" & Chr(0) & "*.doc" & 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 = strStartDir
OpenFile.lpstrTitle = strTitle
OpenFile.flags = OFN_CREATEPROMPT
lReturn = GetOpenFileName(OpenFile)
If lReturn = 0 Then
Else
' trim null char off return value
LaunchCdWithOwner = Trim(Left(OpenFile.lpstrFile, InStr(1, OpenFile.lpstrFile, vbNullChar) - 1))
' set the start dir by trimming the file name off the return value
Dim fn As String
fn = Trim(Left(OpenFile.lpstrFileTitle, InStr(1, OpenFile.lpstrFileTitle, vbNullChar) - 1))
strStartDir = Trim(Left(LaunchCdWithOwner, InStr(1, LaunchCdWithOwner, fn) - 1))
End If
End Function
|