Hello,
I'm using an API call to open the Windows "File Open" Dialog form. I can open the form, but I need to be able to capture the file path that the user selects. Then I want to store that path in field on my form. Below is the code I'm using. The append works when I use the string "Matt is Cool", but when I comment that line out and use the line below it nothing happens. I've gone through the debug and there is a value in the OpenFile.lpstrFile. Actually the path or file name the user selected. Any help would surely be appreciated!
Matt
Code 1:
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
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
>>>This code runs on Click of my Command Button:>>>
Private Sub cmdGetPath_Click()
Dim OpenFile As OPENFILENAME
On Error GoTo Error_CmdGetPath
Dim lReturn As Long
Dim sFilter As String
OpenFile.lStructSize = Len(OpenFile)
sFilter = "Word Documents (*.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 = "C:\"
OpenFile.lpstrTitle = "Select a Project Charter"
OpenFile.flags = 0
lReturn = GetOpenFileName(OpenFile)
If lReturn = 0 Then
MsgBox "The User pressed the Cancel Button"
Else
Me.Goals = "matt is cool"
'Me.Goals = OpenFile.lpstrFile
End If
Error_CmdGetPath:
End Sub
I'm using an API call to open the Windows "File Open" Dialog form. I can open the form, but I need to be able to capture the file path that the user selects. Then I want to store that path in field on my form. Below is the code I'm using. The append works when I use the string "Matt is Cool", but when I comment that line out and use the line below it nothing happens. I've gone through the debug and there is a value in the OpenFile.lpstrFile. Actually the path or file name the user selected. Any help would surely be appreciated!
Matt
Code 1:
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
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
>>>This code runs on Click of my Command Button:>>>
Private Sub cmdGetPath_Click()
Dim OpenFile As OPENFILENAME
On Error GoTo Error_CmdGetPath
Dim lReturn As Long
Dim sFilter As String
OpenFile.lStructSize = Len(OpenFile)
sFilter = "Word Documents (*.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 = "C:\"
OpenFile.lpstrTitle = "Select a Project Charter"
OpenFile.flags = 0
lReturn = GetOpenFileName(OpenFile)
If lReturn = 0 Then
MsgBox "The User pressed the Cancel Button"
Else
Me.Goals = "matt is cool"
'Me.Goals = OpenFile.lpstrFile
End If
Error_CmdGetPath:
End Sub