473,406 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to create attachments in 2003?

374 256MB
I have made a database which is used to record information where users are starting to ask to be able to attach "evidence" to records.

This evidence could be a pdf document, word document, image etc

Now I have researched a little and found most sites tell you to use an OLEObject to do this. However the file size is really hit hard by doing this. So here is my solution...

Users click attach on a form and use the windows open file dialog to find the path. They then click open.However instead of opening the path two things occur:

The file is copied to a central folder on the server (where my back end is kept). This then updates a table which contains a list of all files within the folder. This list of files just contains a unique reference number, the file extension and also the path to the file.

My form then shows the attachment as a hyperlink within a subform (can have mutliple records attached). The subform is ofcourse linked to the main record via the parent ID number. This for instance could be displayed within a datasheet view with the hyperlinks beside the unique ID and then the file type in a 3rd column.Users can click the hyperlink to open the file which is the path to the copy within the back end file storage folder.

Any ideas if anything like this has been done before or whether this sounds feasable? The coding behind it should seem relatively OK using vba I expect.

Anyway, thoughts please.
Nov 29 '10 #1
6 3306
ADezii
8,834 Expert 8TB
Your approach is definitely feasible as well as practical. Personally, I avoid the use of Hyperlinks. I'll usually display Descriptive Text in the Field such as: 3rd Quarter Sales for 2010. This Text will be formatted as Underline, Blue, and possibly Italic to set it off as well as to mimic the look of a Hyperlink. In the Dbl-Click() Event of the Control, I'll perform a DLookup() to retrieve the Absolute Path to the File, then execute it directly based solely on its Extension. Again, this is the simply the System that I like to use, and I am not saying that it is a better/worse than any other.
Nov 29 '10 #2
munkee
374 256MB
Thanks for the reply Adezii, I have begun creating the code now. Do you have any reason why you avoid the usage of hyperlinks?

Also have you seen similar set ups being used in applications for storing attachments as I described? Just wanting to make sure I am not covering anything which could be easily bypassed with a quicker method.
Nov 29 '10 #3
ADezii
8,834 Expert 8TB
There have been similar Threads before covering this very Topic, usually under 'Storing of Images in a Database' or related Topic. You can research these Threads to cover all bases.

P.S. - I do believe that I can save you a lot of time and effort. Here is an Application that I developed for a User awhile ago. It will Open the Office File Dialog, allow the User to select any File (*.*), then write that File to a Text Box whose Control Source is a Hyperlink Field, while displaying the Caption of the Hyperlink only. Be sure that the Reference to the Microsoft Office XX.X Object Library is made. Download the Attachment and let me know what you think.
Attached Files
File Type: zip FileDialog.zip (14.4 KB, 211 views)
Nov 29 '10 #4
munkee
374 256MB
Thanks for that ADezii, it has helped me with understanding a lot of the properties associated with the file dialog that I didnt know about.

I will be using the primary key of the parent to make a new folder if it does not exist and then transfer the file over.

The basic set up so far:

Expand|Select|Wrap|Line Numbers
  1. Sub copyfile()
  2. Dim SourceFile, DestinationFile As String
  3. Dim StrIDNum As Integer
  4. Dim fso As Object
  5. Dim Strfol As String
  6.  
  7. 'Create generic error handler
  8. On Error GoTo Ouch
  9.  
  10. 'Open up a dialog for us to select a file to attach
  11. 'Find the file name of the file we selected 4th in our delimited array
  12.     SourceFile = Split(OpenDialog, "\", , vbTextCompare)(4)
  13.  
  14. 'Select the ID number to use to archive our attachments into
  15.     StrIDNum = 400 'Replace this with a reference to ID number of parent record I.E. me.parent.nccid
  16.  
  17. 'Create the destination folder path
  18.     Strfol = "C:\Documents and Settings\mobbe00C\Desktop\nonconformancereports\" & StrIDNum & "\" ' change to match the folder path"
  19.  
  20. 'Check if the destination folder exists, if not create it
  21. Set fso = CreateObject("Scripting.FileSystemObject")
  22.     If Not fso.FolderExists(Strfol) Then
  23.         fso.CreateFolder (Strfol)
  24.     Else
  25.     End If
  26.  
  27. 'Create the destination file string, which will be equal to our folder and sourcefile name
  28.     DestinationFile = "C:\Documents and Settings\mobbe00C\Desktop\nonconformancereports\" & StrIDNum & "\" & SourceFile    ' Define target file name.
  29.  
  30. 'Copy the file from the source to the destination folder
  31.     FileCopy SourceFile, DestinationFile
  32.  
  33. LeaveIt:
  34.     Exit Sub
  35.  
  36. Ouch:
  37.     MsgBox Err.Number & "-" & Err.Description
  38.     Resume LeaveIt
  39. End Sub
  40.  
  41. Function OpenDialog()
  42.     Dim fd As FileDialog
  43.     Set fd = Application.FileDialog(msoFileDialogFilePicker)
  44.     Dim vrtSelectedItem As Variant
  45.  
  46.     With fd
  47.     .AllowMultiSelect = False
  48.     .ButtonName = "Attach file"
  49.     .InitialFileName = vbNullString
  50.     .InitialView = msoFileDialogViewDetails
  51.     .Title = "Select a file to attach to the database."
  52.  
  53.         If .Show = -1 Then
  54.             For Each vrtSelectedItem In .SelectedItems
  55.                 OpenDialog = vrtSelectedItem
  56.             Next vrtSelectedItem
  57.         Else
  58.         End If
  59.     End With
  60.  
  61.     Set fd = Nothing
  62.  
  63. End Function
  64.  
  65.  
I just need to work on creating a table and appending a new record each time an item is added. I think I will also sort out a way of deleting the file if the attachment record is removed.
Nov 30 '10 #5
ADezii
8,834 Expert 8TB
Looks good munkee, If you wish to keep things simple, and remove the External Reference to the Scripting Runtime, you can. For me, I always try to use what is intrinsic, as long as it performs the task adequately.
Expand|Select|Wrap|Line Numbers
  1. If Dir$(Strfol, vbDirectory) = "" Then
  2.   MkDir Strfol
  3. End if
Nov 30 '10 #6
munkee
374 256MB
Learn something new everyday, I didnt even know there was a Dir$ function! I'll be using this more often. Thanks
Nov 30 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Python Baby | last post by:
I'm about to try a little test project in Python, but want to make sure I'm on the right foot. Any advice appreciated before I start this. MOST important : I want to make sure I'm not just...
3
by: AspDotNetDeveloper | last post by:
I'm trying to troubleshoot why my ASP application can no longer send file attachments larger than 100K, and I have eliminated many possibilities already, but I'm running out of ideas. I think I...
1
by: moon | last post by:
Wondering if this is possible? Situation: I have a frameset with a few frames in it that loads side graphics, main navigation, subnavigation and content. Everything works fine. Now, I decided...
1
by: muskan | last post by:
Does any body has been done Advamce C++ from ACC Austin?
6
by: Peter Row | last post by:
Hi, I am writing a DLL in VB.NET that implements IHttpHandler.ProcessRequest. This code calls a sub and I need to know if that sub did a response redirect or not. Specifically I need to know...
0
by: Flens | last post by:
Hi, I have code that worked until we upgraded from Exchange 2000 to Exchange 2003 and I now get a catastrophic failure at CreateMailbox (COMException (0x080004005)) I have updated the...
6
by: Kosmos | last post by:
Howdy...I'm still a newbie although I've been working with Access for a couple of months now, it's only been on Fridays (but I've been trying to give back by helping out when I can). Anyways this may...
3
by: ITrishGuru | last post by:
Hi all, For my IT final year project I have to access mail items in outlook 2003 and parse them. I have read and researched on the net and library for about a week now. I have to do the project...
30
Niheel
by: Niheel | last post by:
http://bytes.com/images/howtos/freelance_millions.jpgAccording to India Times, there are groups of freelancers in India making over a millions dollars by providing development and IT services to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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
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,...
0
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...

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.