473,414 Members | 1,964 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Attaching an Attachment in ACCESS SQL

Hi!

I'm new here - I've been searching through the web and other ACCESS DBs for a solution and believe there probably is not one (in the way I want it).

Small Non-Profit, using ACCESS 2013 - DB purpose is to store scanned receipts (already battled with Financial to have receipts stored on a drive).
Each new year, the Receipt table will be wiped and new receipts will be stored table.

Working on an INSERT statement, which normally works well, this is the first time I have add an attachment (as most times I've used links to get to the attached file).

Most controls on the form are unbound so I can load, update and error check them as needed. The problem - is that I cannot find how to use SQL to store the receipt file to the table.

This is the INSERT statement I'm using:
Expand|Select|Wrap|Line Numbers
  1. sMySQL = "INSERT INTO Receipts "
  2.         sMySQL = sMySQL & "([EntryDate], [Purchaser], [ReceiptDate], [ReceiptVendor], ReceiptAmt, ItemList, Reason, Company, InternalCode, ReceiptPayment, receipt) "
  3.         sMySQL = sMySQL & "Values "
  4.         sMySQL = sMySQL & "('" & sEntDate & "', '" & sEmp & "', '" & sRctDate & "', '" & sVendor & "', " & Me.txtAmt & ", '" & sItems & "', '" & sReason & "', " & iCompany & ", " & cmbChrtAccts.Column(1) & ", '" & Me.cmbPay & "', " & Me.Receipt & ");"
  5.  
Then I perform a:
DoCmd.RunSQL sMySQL

Little to my surprise, I receive a "Run-time error '3134': Syntax error in INSERT INTO statement", the SQL statement doesn't see the file. There's a blank at the end of the data and hence, the syntax error.

This is what 'sMySQL' equals at run time:
INSERT INTO Receipts ([EntryDate], [Purchaser], [ReceiptDate], [ReceiptVendor], ReceiptAmt, ItemList, Reason, Company, InternalCode, ReceiptPayment, receipt)
Values
('20151007', 'Vance, Susan', '20150912', 'See' & Chr(39) & 's Candies', 16.2, 'Nuts', 'Wanted to bring something home as a treat', 0, 2003, 'AMEX1003', );

I appreciate any and all help or suggestions on how this can be done if not by SQL.

Kind regards,
Mike
Oct 7 '15 #1
1 4713
zmbd
5,501 Expert Mod 4TB
AFAIK: It is not possible to use SQL to add an file to the attachment field. The last time I played with these, the INSERT action query choked on Lookup/MultiValue/Attachment fields if listed.

IMHO: It is usually not a good idea to store attachments within an Access Database (table capacity>Post#3 ).

You either have to use the attachment control on the form or use VBA and LoadFromFIle and SaveToFile methods.
You might find this thread interesting: How To Manipulate Attachment Fields > Post #6 and the follow-up post#8

You indicate that in the past you've simply used links to the file - IMHO, this would still be the best method to handle the scanned receipts. Once scanned, have a few people with user accounts that can move the scanned file to a directory where only these individuals have read/write/modify security privileges via the operating system. Give the "everyone" user read only privileges.

You could also store a SHA2 or MD5 digest of the file along with the URL to the file. This way, if the file is changed, you have a way to prove this fact (provided of course that no-one replaces the digest of the old with the new :) )
Dec 5 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Petri Savolainen | last post by:
Hello, has anyone seen such a beast? I tried googling, PyPI, Parnassus etc. but could not find any pure-python code nor extensions to interface with any of the existing implementations. I am...
2
by: Tom | last post by:
I'm using Access to work with my data stored in a DB2 database on an AS/400. One of the things that I would like to do is to create code that will attach (link to) all the necessary tables. I...
3
by: Brian Farnhill (MCP VB.NET) | last post by:
Hi, I am having some trouble using the MailMessage object to send an email with more than one attachment. I am working on a web based application where a user can submit information, along...
5
by: Sean | last post by:
Hi... I want to use the macro/sendobject (or any other procedure) to send the contents of a table (very small, ~5 rows/columns) as an Outlook message body, not as an attachment. Access 2000 will...
5
by: handokowidjaja | last post by:
Hi All, I'm trying to automate sending an email with an attachment in our environment (access 97) using Outlook Express ( we dont have MS outlook or other fancy stuff). Does anybody knows how to...
6
by: brendan_gallagher_2001 | last post by:
Hi, Does anyone know how to create an attachment using a stream in classic ASP. I can see that it can be done in ASP.Net as per the article below: Initializes a new instance of the Attachment...
2
by: ARC | last post by:
(sorry for the re-post, but I thought I would put the winmail.dat where it's visible in the subject...thanks!) Hello all, I have a question that I hope someone can help with. I have an Access...
3
by: zaxxon25 | last post by:
I am having an issue with attaching 2 attachments one xip and other excel file with email and sending using perl sendmail. I tried to look on various forums and everywhere i get advice using MIME ::...
0
by: kumar215 | last post by:
Hi All, How can we attach a file in VBA application using access. I have a form1 with button placed on it. On click of button I need to call another form2 from where I need to attach 10 files....
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.