Solved

How to save attachments from Access 2007 to a SQL 2005 database

Posted on 2009-05-14
9
730 Views
Last Modified: 2012-05-07
I have a SQL 2005 database and an Access 2007 front end.

How do i save an attachment to SQL from Access?
0
Comment
Question by:JoseJalapeno
  • 4
  • 3
  • 2
9 Comments
 
LVL 46

Expert Comment

by:tbsgadi
Comment Utility
Hi,
If you're talking about saving files to the database, it's better practice to save files on your file server & just to add the filepath to your Table.

Gary
0
 

Author Comment

by:JoseJalapeno
Comment Utility
Forgive me for being dumb but how do you use that filepath in access to save and retreive the file?
0
 
LVL 41

Expert Comment

by:pcelba
Comment Utility
You have to open the Access table as ADO recordset and save all attachments to disk. Then you may process files on disk and upload them to the SQL Server, if necessary.
'  Instantiate the parent recordset. 

   Set rsEmployees = db.OpenRecordset("Employees")

 

   & Code to move to desired employee

 

   ' Instantiate the child recordset.

   Set rsPictures = rsEmployees.Fields("Pictures").Value 
 

   '  Loop through the attachments.

   While Not rsPictures.EOF

 

      '  Save current attachment to disk in the "My Documents" folder.

      rsPictures.Fields("FileData").SaveToFile _

                  "C:\Documents and Settings\Username\My Documents"

      rsPictures.MoveNext

   Wend

Open in new window

0
 

Author Comment

by:JoseJalapeno
Comment Utility
Sorry, the question was not clear.

What do i put on the form to enable saving and retreiving of attachments?

Say i want to save an attachment relating to a specific record which i have open.
What do i have on the form to enable the action?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 46

Expert Comment

by:tbsgadi
Comment Utility
0
 

Author Comment

by:JoseJalapeno
Comment Utility
As the original subject line says...

How to save attachments from Access 2007 to a SQL 2005 database
0
 
LVL 41

Expert Comment

by:pcelba
Comment Utility
We understand your question and our solution will work for you. You need to process two steps:

1) Save the attachment(s) to the disk using either my code or code from tbsgadi's link
2) Import the file to SQL Server using e.g. following solution:
http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SQL-Server-2005/Q_22661404.html?sfQueryTermInfo=1+10+2005+binari+file+import+server+sql

Of course the data structures are no same for Access and SQL Server because SQL Server does not support same attachment structure as Access 2007. You may also store just filename and reserve some folder for such attachment files on SQL Server hosting machine.

Easy (one click) solution does not exist. SQL Server has weak support for it.

Another approach is to leave attachments in Access database.
0
 

Author Comment

by:JoseJalapeno
Comment Utility
Bill Gaqtes has a lot to answer for.

The "HOWTO: Access and Modify SQL Server BLOB Data by Using the ADO Stream Object" link won't open
I even googled the name, still no go.

I am not famliar with binary data in coding. I need users to be able to add and retreive files on the fly.
If i cant put the file in the database i could link to a folder if i knew how.
What control goes on a form to link to a folder somewhere
0
 
LVL 41

Accepted Solution

by:
pcelba earned 500 total points
Comment Utility
If you mean this link http://support.microsoft.com/?kbid=258038 it works for me. But it is not necessary to use this solution because several other ways exist.

As I wrote earlier, your task will need some learning and VB programming. It is really not integrated in a box as Access is trying to convince us and all Office users...

You have to start from beginning, e.g. add a button to your form and try to write some VB code in its Click method. The VB code allows to access all folders on your computer (if users have permissions to do it), the VB code can access all form properties and methods, the VB code can access data in Access database etc. Just look at existing solutions and templates which are offered in Access 2007 and do it similar way.

You are asking in SQL Server 2005 zone. So you may obtain answers about binary files import to SQL Server here but probably not VB coding in Access 2007. If you ask same question in Access programming zone, you could get more relevant answers.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now