Andy Kim via AccessMonster.com <fo***@nospam.AccessMonster.com> wrote:
Can anyone help with providing an option to attach files such as MS
Word or Excel document to a database record and be able to view
without having to store the document as an OLE object? I want to be
able to link the darabase record to many related files.
Thanks,
Sure. I simply store the full path name of the file in a text field
(using a file dialog to choose your file). I have a table allowing
multiple file "attachments" per employee (displayed in a Listbox).
I then have some code to open the file (should work with any file
extension recognised by Windows and if the program accepts a file to
open in the command line when callling it). The code calls a function
that gets the program associated with the file extension.
eg. (This is a bit messy but should give you the idea)
Private Sub btnOpen_Click()
'get program associated with file extension (pass file and folder
seperately)
ProgPath = fFindEXE(Me![FileList].Column(1), Me![FileList].Column(2))
'strip null characters if any??
For i = 1 To Len(ProgPath)
c = Mid(ProgPath, i, 1)
If c <> Chr(0) Then
NewProgPath = NewProgPath & c
End If
Next
'strip spaces from start/end of string
If Len(NewProgPath) > 0 Then NewProgPath = Trim(NewProgPath)
'remove /n being added on Win95c computers??
If Mid(NewProgPath, Len(NewProgPath) - 1, 1) = "/" Then NewProgPath =
Left(NewProgPath, Len(NewProgPath) - 2)
FilePath = Me![FileList].Column(2) & Me![FileList].Column(1)
'construct as if writing a shortcut, adding quotes etc
FullPath = Chr(34) & NewProgPath & Chr(34) & Chr(32) & Chr(34) &
FilePath & Chr(34)
'open program/file
r = Shell(FullPath, vbNormalFocus)
End Sub
--------------------------
Const cMAX_PATH = 260
Const ERROR_NOASSOC = 31
Const ERROR_FILE_NOT_FOUND = 2&
Const ERROR_PATH_NOT_FOUND = 3&
Const ERROR_BAD_FORMAT = 11&
Const ERROR_OUT_OF_MEM = 0
Private Declare Function apiFindExecutable Lib "shell32.dll" _
Alias "FindExecutableA" _
(ByVal lpFile As String, _
ByVal lpDirectory As String, _
ByVal lpResult As String) _
As Long
Function fFindEXE(stFile As String, _
stDir As String) _
As String
'Usage Example:
' ?fFindEXE("test.xls","c:\temp")
'
On Error GoTo fFindEXE_err
Dim lpResult As String
Dim lngRet As Long
lpResult = Space(cMAX_PATH)
lngRet = apiFindExecutable(stFile, stDir, lpResult)
If lngRet > 32 Then
fFindEXE = lpResult
Else
Select Case lngRet:
Case ERROR_NOASSOC: fFindEXE = "Error: No Association"
Case ERROR_FILE_NOT_FOUND: fFindEXE = "Error: File Not
Found"
Case ERROR_PATH_NOT_FOUND: fFindEXE = "Error: Path Not
Found"
Case ERROR_BAD_FORMAT: fFindEXE = "Error: Bad File Format"
Case ERROR_OUT_OF_MEM: fFindEXE = "Error: Out of Memory"
End Select
End If
fFindEXE_exit:
Exit Function
fFindEXE_err:
MsgBox Err.Description, 48, "Error in fFindEXE()"
Resume fFindEXE_exit
End Function
--
regards,
Bradley
A Christian Response
http://www.pastornet.net.au/response