Private Declare Function GetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Public CDCaption, CDSearchString, CDInitDir As String
Public 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 LaunchCD(strForm As Form) As String
Dim OpenFile As OPENFILENAME
Dim lReturn As Long
Dim sFilter As String
OpenFile.lStructSize = Len(OpenFile)
OpenFile.hwndOwner = strForm.hwnd
sFilter = CDSearchString
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 = CDInitDir
OpenFile.lpstrTitle = CDCaption
OpenFile.flags = 0
lReturn = GetOpenFileName(OpenFile)
If lReturn = 0 Then
LaunchCD = "None Selected"
Else
LaunchCD = Trim(Left(OpenFile.lpstrFile, InStr(1, OpenFile.lpstrFile, vbNullChar) - 1))
End If
End Function
Function MakeFilterString(ParamArray varFilt() As Variant) As String
Dim strFilter As String
Dim intRes As Integer
Dim intNum As Integer
intNum = UBound(varFilt)
If (intNum <> -1) Then
For intRes = 0 To intNum
strFilter = strFilter & varFilt(intRes) & vbNullChar
Next
If intNum Mod 2 = 0 Then
strFilter = strFilter & "*.*" & vbNullChar
End If
strFilter = strFilter & vbNullChar
End If
MakeFilterString = strFilter
End Function
Private Sub cmdGetFilepath_Click()
Dim strPath As String
_
_
_
CDSearchString = MakeFilterString("Graphic Files (*.bmp;*.gif;*.jpg;*.png,*.wmf)", _
"*.bmp;*.gif;*.jpg;*.png,*.wmf", "All Files (*.*)", "*.*")
CDCaption = "Select File to Attach..."
If IsNull([txtFilePath]) Or Me.txtFilePath = "" Then
CDInitDir = "C:\MyDocuments\MyPictures"
Else
CDInitDir = [txtFilePath]
End If
strPath = LaunchCD(Me)
If Not strPath = "None Selected" Then
Me.txtImagepath = strPath
End If
End Sub