By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,656 Members | 968 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,656 IT Pros & Developers. It's quick & easy.

Problem adding attachments in Access 2007

P: 2
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
Share this Question
Share on Google+
4 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
What is the data type of the field 'filedata'? Is it an ole object?

Mary
Dec 9 '06 #2

P: 2
the "filedata" field is a built in field to manage attachments in Access 2007.
Dec 9 '06 #3

nico5038
Expert 2.5K+
P: 3,072
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
Expert Mod 15k+
P: 31,270
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

Post your reply

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