Solved

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

Posted on 2009-05-14
9
735 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 41

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
 

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
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.

 
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 41

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 41

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

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.

Question has a verified solution.

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

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

932 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

15 Experts available now in Live!

Get 1:1 Help Now