473,320 Members | 1,952 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,320 software developers and data experts.

button attach file to Object OLE field

EJaques
(Using Access 2003)

I have a an Object OLE field in a table where users can insert Excel sheets, Word Docs, Pdfs etc.

I need to create a button on a formulaire that allows the user to browse for, select and attach the file. The file must appear as an icon that can be double clicked on to be opened. The file should be stocked in the DB.

I can make a dialog box appear and browse for the file and copy the path into the field using this code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub AttachButton_Click()
  2.   Dim varFile As Variant
  3.  
  4.   With Application.FileDialog(msoFileDialogFilePicker)
  5.     With .Filters
  6.       .Clear
  7.     End With
  8.     .AllowMultiSelect = False
  9.     .InitialFileName = vbNullString
  10.     .InitialView = msoFileDialogViewDetails
  11.  
  12.     If .Show = True Then
  13.       For Each varFile In .SelectedItems
  14.         Me![File] = varFile
  15.       Next
  16.     Else
  17.       MsgBox "No file attached ! "
  18.     End If
  19.   End With
  20. End Sub
Thanks to: ADezii
(see http://bytes.com/topic/access/answer...ord-attachment)

But it needs to be an object sitting there, not just the path to the file.
Any help or alternative suggestions would be appreciated.

e
Aug 5 '09 #1
10 18807
ADezii
8,834 Expert 8TB
@EJaques
Rather than go into a detailed explanation, I've created a simple Database and made it available to you as an Attachment. Clicking on the Insert OLE Object Command Button will:
  1. Open the Insert Object Dialog Box, from which you will:
    1. Select Create From File
    2. Browse ==> Select File to Insert ==> OK
    3. Select Display as Icon ==> OK
  2. The OLE Object will now be inserted into the OLE Object Field and displayed as an Icon.
  3. Double-Clicking on the Icon while in Form View will Open the File represented as an Icon in the Registered OLE Server for that File Type.
  4. No need for the File Dialog since the Insert Object Dialog will simply replace it.
  5. Good Luck, and Good Night!
Attached Files
File Type: zip OLE Object.zip (11.9 KB, 2477 views)
Aug 5 '09 #2
Thank you that works very well
Aug 21 '09 #3
ADezii
8,834 Expert 8TB
@EJaques
You are quite welcome.
Aug 21 '09 #4
@ADezii
Can you pls provide the source code for the attachment, as I am new to VBA
Jun 15 '10 #5
ADezii
8,834 Expert 8TB
@kumar215
  1. Download the Attachment
  2. Set the Display Type Property of the Bound Object Frame to Icon
Jun 15 '10 #6
@ADezii
Thanks for reply, How can I get the file path name of file selected by using bound control ?
I need to show the complet file location in some text box.
Jun 16 '10 #7
ADezii
8,834 Expert 8TB
@kumar215
Download the Attachment which should say it all.
Attached Files
File Type: zip OLE Object.zip (15.8 KB, 1140 views)
Jun 16 '10 #8
Thank you so much! This was extremely helpful!
Feb 10 '12 #9
Hishow
14
Thanks a lot. Useful for me too
May 12 '16 #10
zmbd
5,501 Expert Mod 4TB
It should be pointed out for those that come across this thread that it's not normally advisable to store attachments within an access database, doing so consumes a lot of the limited space within the database file and if the database is corrupted you will lose your documents.

A better option is to store links to the appropriate file and then Shell() out the file or use the appropriate Office-Automation to instance the correct program for the Office document.
May 13 '16 #11

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

Similar topics

3
by: Ben | last post by:
Hi all, i have file input field in a form like this: <input name="isbn" type="text" size="25" value="<?php echo $_POST ?>" /> <input name="image" type="file" size="25" value="<?php echo...
0
by: travis ray | last post by:
Hi, I have an extension in which a file object is created in python and passed down to a c extension which attempts to read from it or write to it. Writing to the file pointer seems to work...
0
by: Sandi | last post by:
I have a simple problem: I have an Access database (images.mdb) that has 2 columns: one is the id of the picture (an integer) and one (column named picture) is a field of type OLE Object which...
1
by: ohb | last post by:
Hello, is someone have a example of c# source of a service which is reading a attach file of an email.? Thank you. OHB.
2
by: ohb | last post by:
Hello, Is it possible to parse a attach file in a email ? ohb
3
by: Sandi | last post by:
I have a simple problem: I have an Access database (images.mdb) that has 2 columns: one is the id if the picture (an integer) and one (column named picture) is a field of type OLE Object which...
8
by: Mark | last post by:
Hello. I am attempting to write binary data from a file to an OLE Object field, and then write the file back out from the database. I am reading and writing the files in binary mode, and using...
3
by: Vibhu | last post by:
Hello All, I have a input box on the HTML page with the type set to file. What I want is that when the value changes in the file textbox, it should give me the full file path. I have even tried...
7
by: RRsonawane11 | last post by:
Hello, Can anyone know how to write asp code to attach one file and email it to a specified email address. The attach file is the client choose from their Local Harddisk, just like we ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.