473,498 Members | 1,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Attaching an Attachment in ACCESS SQL

1 New Member
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 4729
zmbd
5,501 Recognized Expert Moderator Expert
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
2935
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
1766
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
2229
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
2442
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
539
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
10427
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
2299
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
5937
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
1249
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
7126
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
7005
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
7210
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...
1
6891
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
5465
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,...
1
4916
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1424
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
659
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
293
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.