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
Solved

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

Posted on 2009-05-14
9
745 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
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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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
 
LVL 46

Expert Comment

by:tbsgadi
ID: 24383247
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 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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