Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Common Dialog Box
Message
From
11/08/2001 18:27:07
Michael Tustison
Professional Services Industries
Homewood, Illinois, United States
 
 
To
05/08/2001 17:13:03
Michael Tustison
Professional Services Industries
Homewood, Illinois, United States
General information
Forum:
Microsoft Office
Category:
Access
Miscellaneous
Thread ID:
00539927
Message ID:
00542688
Views:
14
I found the code!

Type tagOPENFILENAME
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

Private OPENFILENAME As tagOPENFILENAME

Global Const OFN_READONLY = &H1
Global Const OFN_OVERWRITEPROMPT = &H2
Global Const OFN_HIDEREADONLY = &H4
Global Const OFN_NOCHANGEDIR = &H8
Global Const OFN_SHOWHELP = &H10
Global Const OFN_ENABLEHOOK = &H20
Global Const OFN_ENABLETEMPLATE = &H40
Global Const OFN_ENABLETEMPLATEHANDLE = &H80
Global Const OFN_NOVALIDATE = &H100
Global Const OFN_ALLOWMULTISELECT = &H200
Global Const OFN_EXTENSIONDIFFERENT = &H400
Global Const OFN_PATHMUSTEXIST = &H800
Global Const OFN_FILEMUSTEXIST = &H1000
Global Const OFN_CREATEPROMPT = &H2000
Global Const OFN_SHAREAWARE = &H4000
Global Const OFN_NOREADONLYRETURN = &H8000
Global Const OFN_NOTESTFILECREATE = &H10000
Global Const OFN_SHAREFALLTHROUGH = 2
Global Const OFN_SHARENOWARN = 1
Global Const OFN_SHAREWARN = 0

Declare Function apiGetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (OPENFILENAME As tagOPENFILENAME) As Long
Declare Function lstrcpy& Lib "kernel32" (ByVal lpDestString As Any, ByVal lpSourceString As Any)
Public Function OpenCommDlgFile(defFileName) As String
Dim Message$, Filter$, filename$, FileTitle$, DefExt$
Dim Title$, szCurDir$, APIResults%

'*Define the filter string and allocate space in the "c" string
'Filter$ = "Text File(*.txt)" & Chr$(0) & "*.TXT" & Chr$(0) & "All Files(*.*)" & Chr$(0) & "*.*" & Chr$(0)
'Filter$ = "Database(*.mdb)" & Chr$(0) & "*.mdb" & Chr$(0) & "All Files(*.*)" & Chr$(0) & "*.*"
Filter$ = "Excel Spreadsheet(*.xls)" & Chr$(0) & "*.XLS" & Chr$(0) & "All Files(*.*)" & Chr$(0) & "*.*" & Chr$(0)

'* Allocate string space for the returned strings.
filename$ = Chr$(0) & Space$(255) & Chr$(0)
FileTitle$ = Space$(255) & Chr$(0)

'* Give the dialog a caption title.
'Title$ = "Select File to Import"
Title$ = "Locate " & defFileName & Chr$(0)

'* If the user does not specify an extension, append MDB.
'DefExt$ = "TXT" & Chr$(0)
'DefExt$ = "MDB" & Chr$(0)
DefExt$ = "XLS" & Chr$(0)

'* Set up the default directory
szCurDir$ = CurDir$ & Chr$(0)


'* Set up the data structure before you call the GetOpenFileName
OPENFILENAME.lStructSize = Len(OPENFILENAME)
OPENFILENAME.hwndOwner = 0&
OPENFILENAME.lpstrFilter = Filter$
OPENFILENAME.nFilterIndex = 1
OPENFILENAME.lpstrFile = filename$
OPENFILENAME.nMaxFile = Len(filename$)
OPENFILENAME.lpstrFileTitle = FileTitle$
OPENFILENAME.nMaxFileTitle = Len(FileTitle$)
OPENFILENAME.lpstrTitle = Title$ 'lstrcpy(Title$, Title$)
OPENFILENAME.Flags = OFN_FILEMUSTEXIST ' Or OFN_READONLY
OPENFILENAME.lpstrDefExt = DefExt$
OPENFILENAME.hInstance = 0
OPENFILENAME.lpstrCustomFilter = 0
OPENFILENAME.nMaxCustFilter = 0
OPENFILENAME.lpstrInitialDir = szCurDir$
OPENFILENAME.nFileOffset = 0
OPENFILENAME.nFileExtension = 0
OPENFILENAME.lCustData = 0
OPENFILENAME.lpfnHook = 0
OPENFILENAME.lpTemplateName = 0

APIResults% = apiGetOpenFileName(OPENFILENAME)

If APIResults% <> 0 Then
filename$ = OPENFILENAME.lpstrFile
OpenCommDlgFile = Left$(filename$, InStr(filename$, Chr$(0)) - 1)
Else
OpenCommDlgFile = ""
End If

End Function

Public Function OpenCommDlg(defFileName As String) As String
Dim Message$, Filter$, filename$, FileTitle$, DefExt$
Dim Title$, szCurDir$, APIResults%

'*Define the filter string and allocate space in the "c" string
Filter$ = "Microsoft Access Databases(*.mdb)" & Chr$(0) & "*.MDB" & Chr$(0)

'* Allocate string space for the returned strings.
filename$ = Chr$(0) & Space$(255) & Chr$(0)
FileTitle$ = Space$(255) & Chr$(0)

'* Give the dialog a caption title.
Title$ = "Locate " & defFileName & Chr$(0)

'* If the user does not specify an extension, append MDB.
DefExt$ = "MDB" & Chr$(0)

'* Set up the default directory
'szCurDir$ = "C:\PSI:\IOB" 'CurDir$ & Chr$(0)
szCurDir$ = CurDir$ & Chr$(0)

'* Set up the data structure before you call the GetOpenFileName
OPENFILENAME.lStructSize = Len(OPENFILENAME)
OPENFILENAME.hwndOwner = 0&
OPENFILENAME.lpstrFilter = Filter$
OPENFILENAME.nFilterIndex = 1
OPENFILENAME.lpstrFile = filename$
OPENFILENAME.nMaxFile = Len(filename$)
OPENFILENAME.lpstrFileTitle = FileTitle$
OPENFILENAME.nMaxFileTitle = Len(FileTitle$)
OPENFILENAME.lpstrTitle = Title$ 'lstrcpy(Title$, Title$)
OPENFILENAME.Flags = OFN_FILEMUSTEXIST ' Or OFN_READONLY
OPENFILENAME.lpstrDefExt = DefExt$
OPENFILENAME.hInstance = 0
OPENFILENAME.lpstrCustomFilter = 0
OPENFILENAME.nMaxCustFilter = 0
OPENFILENAME.lpstrInitialDir = szCurDir$
OPENFILENAME.nFileOffset = 0
OPENFILENAME.nFileExtension = 0
OPENFILENAME.lCustData = 0
OPENFILENAME.lpfnHook = 0
OPENFILENAME.lpTemplateName = 0

APIResults% = apiGetOpenFileName(OPENFILENAME)

If APIResults% <> 0 Then
filename$ = OPENFILENAME.lpstrFile
OpenCommDlg = Left$(filename$, InStr(filename$, Chr$(0)) - 1)
Else
OpenCommDlg = ""
End If

End Function
Previous
Reply
Map
View

Click here to load this message in the networking platform