Anyone !
On a form i have a button that opens the open file dialog box and after selecting a file path I want it to store that filepath in a textbox on that form.
I so far have the the button functioning and the open file dialog box opening, but getting the filepath to display in a textbox and storing it is what I'm stuck with.
The below code i found here and I'm using it to open the dialog box. I've used an expression in a command button to run the function ap_fileopen.
Please Any advice?
BROWSE BUTTON CODE:
Option Compare Database
Option Explicit
Private Declare Function ap_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
Public Function ap_FileOpen(Optional strTitle As String = "Open File", _
Optional strFileName As String = "", _
Optional strFilter As String = "" As String
Dim OpenFile As OPENFILENAME
Dim lngReturn As Long
If Len(strFileName) = 0 Then
strFileName = String(255, 0)
End If
If Len(strFilter) = 0 Then
strFilter = "Image Files (*.*)" & Chr(0) & _
"*.*" & Chr(0)
End If
OpenFile.lStructSize = Len(OpenFile)
OpenFile.lpstrFilter = strFilter
OpenFile.nFilterIndex = 1
OpenFile.lpstrFile = strFileName + _
Space(255 - Len(strFileName))
OpenFile.nMaxFile = 255
OpenFile.lpstrFileTitle = strFileName
OpenFile.nMaxFileTitle = OpenFile.nMaxFile
OpenFile.lpstrInitialDir = CurrentProject.Path
OpenFile.lpstrTitle = strTitle
OpenFile.flags = 0
ap_GetOpenFileName OpenFile
ap_FileOpen = Left(OpenFile.lpstrFile, _
InStr(OpenFile.lpstrFile, Chr$(0)) - 1)
End Function
On a form i have a button that opens the open file dialog box and after selecting a file path I want it to store that filepath in a textbox on that form.
I so far have the the button functioning and the open file dialog box opening, but getting the filepath to display in a textbox and storing it is what I'm stuck with.
The below code i found here and I'm using it to open the dialog box. I've used an expression in a command button to run the function ap_fileopen.
Please Any advice?
BROWSE BUTTON CODE:
Option Compare Database
Option Explicit
Private Declare Function ap_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
Public Function ap_FileOpen(Optional strTitle As String = "Open File", _
Optional strFileName As String = "", _
Optional strFilter As String = "" As String
Dim OpenFile As OPENFILENAME
Dim lngReturn As Long
If Len(strFileName) = 0 Then
strFileName = String(255, 0)
End If
If Len(strFilter) = 0 Then
strFilter = "Image Files (*.*)" & Chr(0) & _
"*.*" & Chr(0)
End If
OpenFile.lStructSize = Len(OpenFile)
OpenFile.lpstrFilter = strFilter
OpenFile.nFilterIndex = 1
OpenFile.lpstrFile = strFileName + _
Space(255 - Len(strFileName))
OpenFile.nMaxFile = 255
OpenFile.lpstrFileTitle = strFileName
OpenFile.nMaxFileTitle = OpenFile.nMaxFile
OpenFile.lpstrInitialDir = CurrentProject.Path
OpenFile.lpstrTitle = strTitle
OpenFile.flags = 0
ap_GetOpenFileName OpenFile
ap_FileOpen = Left(OpenFile.lpstrFile, _
InStr(OpenFile.lpstrFile, Chr$(0)) - 1)
End Function