473,487 Members | 2,674 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Attching files

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,
Nov 13 '05 #1
2 1308
Andy Kim via 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,
What I do...

Add a ComboBox whose RowSource is a table where you store the paths to the files
attached to the current record. UNION the RowSource so it can have "< Add New" as the first choice.
In the AfterUpdate method of the ComboBox check to see what was chosen. If an
existing attachment then use Shell or FollowHyperlink to open it. If "< Add New" was chosen then display the FileOpen dialog which the user can use to select

a new file for attaching. The path returned is then stored into the table used
as the RowSource for the ComboBox and the ComboBox is Requeried.

In my case the file path table also has a description field which I prompt the
user for with an InputBox and that is the column actually displayed in the list.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #2
Br
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
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
14140
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
44
3984
by: Xah Lee | last post by:
here's a large exercise that uses what we built before. suppose you have tens of thousands of files in various directories. Some of these files are identical, but you don't know which ones are...
0
6069
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
18
3135
by: JKop | last post by:
Here's what I know so far: You have a C++ project. You have source files in it. When you go to compile it, first thing the preprocessor sticks the header files into each source file. So now...
3
3072
by: pooja | last post by:
Suppose i have created a class c1 with f1()in c1.cpp and included this c1.cpp in file1.cpp file , which is also having main() by giving the statement #include "c1.cpp". the same i can do by...
11
5537
by: ambika | last post by:
Iam just trying to know "c". And I have a small doubt about these header files. The header files just contain the declaration part...Where is the definition for these declarations written??And how...
22
2974
by: Daniel Billingsley | last post by:
Ok, I wanted to ask this separate from nospam's ridiculous thread in hopes it could get some honest attention. VB6 had a some simple and fast mechanisms for retrieving values from basic text...
18
2269
by: UJ | last post by:
Folks, We provide custom content for our customers. Currently we put the files on our server and people have a program we provide that will download the files. These files are usually SWF, HTML or...
3
5149
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
0
7106
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7137
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7349
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5442
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4874
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
600
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
267
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.