Help,
I am trying to have a (file open box) to get a file path and store that information into a table.
I have read these topics, however, I am not advanced to understand how to do these things
On my form there is a field with the control source set to "1" on my table. I also have a button linked to the code below that opens the file open box. and returns a MSGBOX with the file path.
How do i put that information into my form that will update the table using a Module?
Please be as specific as possable.
Thanks
Foocat
going on 5 hours now!!!
Here is my code
Option Compare Database
Option Explicit
Private Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
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
Private Const OFN_HIDEREADONLY = &H4
Private Const OFN_NOCHANGEDIR = &H8
Private Const OFN_SHAREAWARE = &H4000
Public Const OFN_CREATEPROMPT = &H2000
Private Const MAX_PATH = 260
Public Function getfile(Optional InitialDir As String, _
Optional FilterMessage As String = "Choose File", _
Optional FilterSkelton As String = "*.*", _
Optional File As String = "File Name", _
Optional Title As String = "Use the Open Button to Select"
As String
getfile = getPath(CurDir$, FilterMessage, FilterSkelton, File, Title)
End Function
Public Function getPath( _
Optional InitialDir As String, _
Optional FilterMessage As String = "Choose Folder Only", _
Optional FilterSkelton As String = "*|*", _
Optional File As String = "Folders Only", _
Optional Title As String = "Use the Open Button to Select"
As String
Dim CommDlgError As Long
Dim OFN As OPENFILENAME
If Len(InitialDir) = 0 Then InitialDir = CurDir$()
With OFN
.lStructSize = Len(OFN)
.lpstrFilter = FilterMessage & vbNullChar & FilterSkelton & String(2, vbNullChar)
.lpstrFile = File & String(MAX_PATH - Len(File), vbNullChar)
.nMaxFile = MAX_PATH
.lpstrInitialDir = InitialDir & vbNullChar
.lpstrTitle = Title
.lpstrFileTitle = String(MAX_PATH, vbNullChar)
.nMaxFileTitle = MAX_PATH
.Flags = OFN_HIDEREADONLY Or OFN_NOCHANGEDIR Or OFN_SHAREAWARE
If GetOpenFileName(OFN) <> 0 Then
' .lpstrFileTitle conatins file name only
If FilterSkelton = "*|*" Then
getPath = Left(.lpstrFile, .nFileOffset)
Else
getPath = .lpstrFile
End If
Else
CommDlgError = CommDlgExtendedError
' if not just a cancel
If CommDlgError <> 0 Then
MsgBox "Common Dialog Error # " & CommDlgError & vbCrLf & vbCrLf & "Consult Common Dialog Documumentation" & vbCrLf & "(in MSDN Library)" & vbCrLf & vbCrLf & "for meaning.", vbCritical, "Cyriv Solutions"
End If
End If
End With
End Function
Sub testgetPath()
MsgBox getPath
End Sub
Sub testgetFile()
MsgBox getfile()
End Sub
I am trying to have a (file open box) to get a file path and store that information into a table.
I have read these topics, however, I am not advanced to understand how to do these things
On my form there is a field with the control source set to "1" on my table. I also have a button linked to the code below that opens the file open box. and returns a MSGBOX with the file path.
How do i put that information into my form that will update the table using a Module?
Please be as specific as possable.
Thanks
Foocat
going on 5 hours now!!!
Here is my code
Option Compare Database
Option Explicit
Private Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
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
Private Const OFN_HIDEREADONLY = &H4
Private Const OFN_NOCHANGEDIR = &H8
Private Const OFN_SHAREAWARE = &H4000
Public Const OFN_CREATEPROMPT = &H2000
Private Const MAX_PATH = 260
Public Function getfile(Optional InitialDir As String, _
Optional FilterMessage As String = "Choose File", _
Optional FilterSkelton As String = "*.*", _
Optional File As String = "File Name", _
Optional Title As String = "Use the Open Button to Select"
getfile = getPath(CurDir$, FilterMessage, FilterSkelton, File, Title)
End Function
Public Function getPath( _
Optional InitialDir As String, _
Optional FilterMessage As String = "Choose Folder Only", _
Optional FilterSkelton As String = "*|*", _
Optional File As String = "Folders Only", _
Optional Title As String = "Use the Open Button to Select"
Dim CommDlgError As Long
Dim OFN As OPENFILENAME
If Len(InitialDir) = 0 Then InitialDir = CurDir$()
With OFN
.lStructSize = Len(OFN)
.lpstrFilter = FilterMessage & vbNullChar & FilterSkelton & String(2, vbNullChar)
.lpstrFile = File & String(MAX_PATH - Len(File), vbNullChar)
.nMaxFile = MAX_PATH
.lpstrInitialDir = InitialDir & vbNullChar
.lpstrTitle = Title
.lpstrFileTitle = String(MAX_PATH, vbNullChar)
.nMaxFileTitle = MAX_PATH
.Flags = OFN_HIDEREADONLY Or OFN_NOCHANGEDIR Or OFN_SHAREAWARE
If GetOpenFileName(OFN) <> 0 Then
' .lpstrFileTitle conatins file name only
If FilterSkelton = "*|*" Then
getPath = Left(.lpstrFile, .nFileOffset)
Else
getPath = .lpstrFile
End If
Else
CommDlgError = CommDlgExtendedError
' if not just a cancel
If CommDlgError <> 0 Then
MsgBox "Common Dialog Error # " & CommDlgError & vbCrLf & vbCrLf & "Consult Common Dialog Documumentation" & vbCrLf & "(in MSDN Library)" & vbCrLf & vbCrLf & "for meaning.", vbCritical, "Cyriv Solutions"
End If
End If
End With
End Function
Sub testgetPath()
MsgBox getPath
End Sub
Sub testgetFile()
MsgBox getfile()
End Sub