473,397 Members | 2,068 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,397 software developers and data experts.

How to insert an attachment into a table through form in ms access 2007

6
hi all,
I would like to insert an attachment object into a table using a form. I have created a table with a field type attachment. But when i am inserting data into table , error is coming.
The error is:
Runtime error: -2147217887
Cannot perform this operation.


Expand|Select|Wrap|Line Numbers
  1. Private Sub cmd_add_save_Click()
  2.  
  3. Dim cmd As ADODB.Command, rs As ADODB.Recordset
  4. Set cmd = New ADODB.Command
  5. cmd.ActiveConnection = CurrentProject.AccessConnection
  6. cmd.CommandType = adCmdUnknown
  7.  
  8. Set rs = New ADODB.Recordset
  9. rs.Open "Purchase", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
  10. With rs
  11.     .AddNew ' create a new record
  12.     .Fields(0) = Me.txt_add_prno
  13.     .Fields(1) = Me.txt_add_prdesc
  14.     .Fields(2) = Me.txt_add_prvalue
  15.     .Fields(3) = Me.txt_pr_date
  16.     .Fields(4) = Me.Purchase_PRNote ' Error occurs at this line. 
  17.  
  18.     .Update
  19. End With
  20. Set rs = Nothing
  21. End Sub
  22.  
Purchase_PRnote is the name of the textbox which contains the attachment.
Mar 20 '12 #1
1 6264
ADezii
8,834 Expert 8TB
Working with an Attachment Field in VBA is bo no means intuitive. I did not have much time, but I did have some success adding Attachments to an Attachment Field in a Table. It is not exactly what you are looking for, but it may point you in the right direction.
Expand|Select|Wrap|Line Numbers
  1. Dim dbs As DAO.Database
  2. Dim rs As DAO.Recordset
  3. Dim rs2 As DAO.Recordset
  4.  
  5. Set dbs = CurrentDb
  6.  
  7. Set rs = dbs.OpenRecordset("Purchase", dbOpenDynaset)
  8.  
  9. Set rs2 = rs.Fields("PRNOTE").Value
  10.  
  11. With rs
  12.   .Edit
  13.     .Fields(0) = Me.txt_add_prno
  14.     .Fields(1) = Me.txt_add_prdesc
  15.     .Fields(2) = Me.txt_add_prvalue
  16.     .Fields(3) = Me.txt_pr_Date
  17.       rs2.AddNew
  18.         rs2.Fields("FileData").LoadFromFile Me!Purchase_PRNOTE
  19.       rs2.Update
  20.   .Update
  21. End With
  22.  
  23. rs.Close
  24. Set rs = Nothing
  25. Set rs2 = Nothing
Mar 22 '12 #2

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

Similar topics

1
by: BMF | last post by:
Howdy, I am mainly a MySQL user but I have been playing with Access 07 a little bit recently. I created a database with 3 tables. Table ID --- userID -- AutoNumber UserInfo -...
1
by: Paldrion | last post by:
How Can I Automatically add an AutoNumber field to a table in Access 2007? If code is needed, please include how I would use the code in an access module, so I can automate this with a macro.
1
by: Paldrion | last post by:
I will need it to be in VBA, since I need to put it in an Access 2007 database and execute it with an Access macro. What I am doing is using a utility to find the hard drives' conditions on...
5
by: sphinney | last post by:
I have data in a few external Access tables that I want to link to my Access 2007 database. Depending on situation (and permissions of the person using the database) I want to dynamically link to...
2
by: ijyoung | last post by:
Am trying to customise automation in Access 2007/Outlook. Using MS template which works ok. However, I have the form set up as a subform an embedded in the main form Although the form works fine in...
12
by: CindySue | last post by:
I would like to be able to copy the current record to a different table. I am tracking donations and I create a new table of donations each year--some of the records will be the same or slightly...
4
cobra35y
by: cobra35y | last post by:
Good Afternoon, I am new to the world of programming. after reviewing this site for info pertaining to my situation, i have declared a loss and posting for help. maybe i am just overlooking the...
2
by: sentimental37 | last post by:
I want to create a table in access 2007 by query not in design view. My table should look like; Serial AutoNumber Name Text Country Text I am using the following query: CREATE TABLE Details...
0
by: sarah2855 | last post by:
Hello, I would like to insert a pivot table in an access report.I was able to create a pivot table chart in Query -> pivot table view but I don't know how to incorporate that in reports. Is this...
5
by: Ruth Myers | last post by:
Hi all - I have created a form to describe digital photographs (JPGs) attached to my database. Along with the attachment image, I've also added a field that displays attachment name. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.