?
Solved

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

Posted on 2009-05-14
9
Medium Priority
?
763 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 46

Expert Comment

by:tbsgadi
ID: 24382920
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
ID: 24383018
Forgive me for being dumb but how do you use that filepath in access to save and retreive the file?
0
 
LVL 42

Expert Comment

by:pcelba
ID: 24383074
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:JoseJalapeno
ID: 24383203
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
 

Author Comment

by:JoseJalapeno
ID: 24383428
As the original subject line says...

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

Expert Comment

by:pcelba
ID: 24384055
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
ID: 24384480
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 42

Accepted Solution

by:
pcelba earned 1500 total points
ID: 24385101
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

764 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