473,466 Members | 1,388 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem adding attachments in Access 2007

2 New Member
I am trying to run the following code as a simple test of adding an attachment through access 2007:

Expand|Select|Wrap|Line Numbers
  1.     Dim rsJob As DAO.Recordset2
  2.     Dim rsChild As DAO.Recordset2
  3.     Dim field As Field2
  4.  
  5.     Set rsJob = Me.Recordset
  6.     Set rsChild = rsJob.Fields("attachments").Value
  7.     Set field = rsChild.Fields("filedata")
  8.  
  9.       rsJob.Edit
  10.       rsChild.AddNew
  11.         field.LoadFromFile ("c:\temp\1.bmp")
  12.       rsChild.Update
  13.       rsJob.Close
  14.  
  15.     Set fld = Nothing
  16.     Set rsChild = Nothing
  17.     Set rsJob = Nothing
I simply want to add an attachment to the currently open form's record.

When it gets to the line field.LoadFromFile ("c:\temp\1.bmp") I get an invalid argument error. Can anyone see what I am doing wrong here?
Dec 7 '06 #1
4 7691
MMcCarthy
14,534 Recognized Expert Moderator MVP
What is the data type of the field 'filedata'? Is it an ole object?

Mary
Dec 9 '06 #2
VoodooFrog
2 New Member
the "filedata" field is a built in field to manage attachments in Access 2007.
Dec 9 '06 #3
nico5038
3,080 Recognized Expert Specialist
Did you try:

field.LoadFromFile "c:\temp\1.bmp"
or
rsChild.Fields("filedata").LoadFromFile "c:\temp\1.bmp"

This is the code from the helpfile:

' Instantiate the parent recordset.
Set rsEmployees = db.OpenRecordset("Employees")

… Code to move to desired employee

' Activate edit mode.
rsEmployees.Edit

' Instantiate the child recordset.
Set rsPictures = rsEmployees.Fields("Pictures").Value

' Add a new attachment.
rsPictures.AddNew
rsPictures.Fields("FileData").LoadFromFile "EmpPhoto39392.jpg"
rsPictures.Update

' Update the parent record
rsEmployees.Update

Nic;o)
Dec 9 '06 #4
NeoPa
32,556 Recognized Expert Moderator MVP
As Nico says, you need to lose the parentheses () from the procedure call
Expand|Select|Wrap|Line Numbers
  1.         field.LoadFromFile "c:\temp\1.bmp"
Dec 10 '06 #5

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

Similar topics

1
by: Espen Sletteng | last post by:
Hello all, I want to create a .NET-based web service that can accept dime-based attachments from a java (Axis)-based client. I have searched for examples that look like this scenario, but...
3
by: Bart Stes | last post by:
Hey Guys, I'm trying to write a very simple thing that allows a user to send an e-mail from a windows form app. I use the System.Web.Mail MailMessage class for this and then send my e-mail...
2
by: Brad | last post by:
I have a web .Net app which sends emails with attachments. After the email is sent I clean up aftermyself and delete the attachments from disk. In upgrading to .Net 2 I changed the email logic...
4
by: Balex | last post by:
Hi I have recently helped somebody converting an Access application into an Access (2002) front-end and an Oracle backend. It worked fine, until he decided to install and use Access 2007...
6
by: Michael Kintner | last post by:
I am looking for add-on tools or code to allow me to attach scanned PDF documents to a database record. I would like to know if there are developer tools out there that can do the following: -...
130
by: Gianni Mariani | last post by:
Attached example CPP files makes it easier to post code and extract code from posts. It's unimaginable at this time where virtually any news reader is capable of dealing with attachments to stick...
9
by: Dave | last post by:
Hi guys, I have just set up a duplicate server running: apache 2.54, mysql 5.04 and php 5.04 This is the same setup as as the server we are using now, apart from the hardware inside. I have...
2
by: ScottM | last post by:
Hi, I am an experienced VB6 programmer but a novice when it comes to MS Access. I have a form for ECO's (Engineering Change Orders) based on the table ECO, and in it I created a subform that is...
1
by: lrw0831 | last post by:
I have an Access database that is used to keep track of issues that the department receives. What we need is a way to add attachments to issues, but only by adding the path name that is a hyperlink...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
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
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.