[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2009-05-14
9
Medium Priority
?
777 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 43

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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

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 43

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 43

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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

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…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

834 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