How to attach documents in ms access using vb6 - ms-access

Good day. I have an Access database with a field using an attachment data type. Is there a way to use Visual Basic 6 to attach my documents, such as images, Word files and PDF files on that database? Specifically on the field using the attachment data type.

Yes, from the LoadFromFile Method.
Snippet below:
Set AttachmentRecordset = RecordSetForTable.Fields("AttachmentFieldName").Value
FileName = "SomePathToAFile"
AttachmentRecordset.AddNew
AttachmentRecordset.Fields("FileData").LoadFromFile (FileName)
AttachmentRecordset.Update

Related

How to import data from external webpage connection in MS Access like excel has Data- WebPage

Like excel has Data=>From Web to import a table in webpage in excel. How can I achieve this in MS Access? I want to data in table in external web page into the MS Access Table. Just Like we can in excel.
I don't want to use any intermediate excel to import data in Access but direct
external html page data into Access.
I want to import the option chain from NSE India into MS Access.
The external webdata is Option chain from NSE india like in URL:
https://nseindia.com/live_market/dynaContent/live_watch/option_chain/optionKeys.jsp?symbolCode=-10003&symbol=NIFTY&symbol=NIFTY&instrument=OPTIDX&date=-&segmentLink=17&segmentLink=17
This was done in Excel but I want to do it in MS Access.
There is no easy way to do this; Access can get the table from the downloaded file, but it will be confused by the double-line headers. It can ignore one line but not two, thus the headers' second line will be read as data scrambling the real data.
Excel just does a better job isolating the table with its headers and values. Your best option, in my opinion, will be to automate Excel, using it to retrieve the page and build the table. Then, from Access, link the prepared worksheet holding the table.
Alternatively, use the function DownloadFile found in my project at GitHub: VBA.PictureUrl, link the file, and create a query (using the linked file as source) where you clean up and convert the retrieved data as needed.

How do I download contents of an html table generated by play 1.2.7 backend on java in xls

I've generated a table using play's #{list} tag and get pretty decent results. Now I need to be able to generate and download an xls version of the table and have no idea what to do. Any pointers at all will be much appreciated
Well you have various options.
Excel will open HTML files. So instead of rendering your table as HTML you can it to stream it to the browser and set the content type as XLS.
While Excel will open it this it will still be an HTML file rather than an XLS(X) document.
You can generate as CSV from your data model and stream this to the browser. Again this will be a CSV rather than a proper XLS(X) document.
There also seem to be some solutions around which can do it using Javscript. See as a starting point: Generate excel sheet from html tables using jquery
Finally you can can use something like Apache POI or JXLS to generate a 'proper' xls(x) document and stream this to the browser. I have some code here that will export HTML to 'proper' xlsx file if this is the route you wish to go. Workflow is then to create some HTML from your data model and use this to convert to Excel rather than having to programmatically build the Excel document using POI. https://github.com/alanhay/html-exporter

The difference between using an OLE Object and an Attachment in Access 2007?

I'm learning Access 2007, and among the list of data types are the OLE Object and the Attachment.
The text has this to say about Attachments:
You can use attachments to store
several files, and even different
types of files, in a single field. The
Attachment field is new for Access
2007 and stores data files more
efficiently than using other fields
like the OLE Object field.
More efficiently than OLE Objects?
What is the purpose and proper use of the Attachment data type? And how is it related to the OLE Object?
WHY THE OLE OBJECT IS A BETTER SOLUTION THAN THE ACCESS ATTACHMENT DATA TYPE
The default user interface for the OLE Object storage system is clumsy. The attachment data field introduced in Access 2007 has an improved user interface making it easier to work with different file types. Unfortunately, beginning in Access 2013 and continuing in Access 2016, Microsoft developed a fatal glitch that they have not addressed with a Windows update. If you have saved a Microsoft Word document in an Access Attachment field, you can edit the Word Document, but it cannot be saved in Access. When you click 'Save' you are prompted to save the document to a file. It won't save to the Access database. Other file types will save to the database such as Excel spreadsheets.
Because of this Microsoft glitch, I was forced to develop an improved user interface for the OLE Object data field. In a nutshell, it is a one to many relationship table that saves the file name and file in an OLE Object data field. The user interface opens file explorer to add the file. I use ShellExucute to open the document via Windows which has much more flexibility to file types than the Access default user interface.
The Access Attachment data type is limited to Microsoft Access databases. The OLE Object data type can be migrated to an SQL Server database where the content within the stored documents can be searched with an SQL Server query. A lot of power there! Just my opinion.
Not an exhaustive answer, but I recently tried to use an OLE object field to store images to be printed through a report.
To make the story short, it does not work very easily, and is restricted to 2 little used image formats.
Using an Attachment field, it works like a charm and you can use .PNG files as well.
Note 1: Attachment is NOT available in .MDB so I had to migrate to ACCDB.
Note 2: OLE Object field can be migrated to SQL Server, Attachment field cannot
Judging from this description, I would say that it is some sort of native binary field.
OLE Object fields were really just containers for OLE objects. They suffered from considerable bloat, and were clumsy to use.

How to extract data from a PDF?

My company receives data from an external company via Excel. We export this into SQL Server to run reports on the data. They are now changing to PDF format, is there a way to reliably port the data from the PDF and insert it into our SQL Server 2008 database?
Would this require writing an app or is there an automated way of doing this?
As already mentioned - you will have to write an app to do this, but ideally you would be able to get the raw data from the external company rather than having to process the PDF.
However, if you do want to extract the data from the PDF, I've used iText and found it to be very powerful, reliable and most importantly - free. It comes in Java and .Net flavours - iTextSharp is the .Net version. It allows you to programatically manipulate PDF documents and it will expose the contents of the PDF to the application that you write.
It all depends on how they've included the data within the PDF. Generally speaking, there's two possible scenarios here:
The data is just a text object within a PDF. You'll need to use a tool to extract the text from the PDF then insert it into your database.
The data is contained within form fields in a PDF. You'll need to use a tool to extract data from the form fields and insert it into your database.
Hopefully scenario #2 applies to you because this is precisely what PDF forms are designed for. Scenario #1 is really just a hack that you'd only use if you didn't have any other options. Extracting plain text from a PDF isn't as easy or accurate as you might expect.
If you're receiving a PDF form then all you need to do is match up the right fields in the PDF form with the corresponding fields in your database and then suck in the data. This process could be entirely automated if you wrote your own application.
Would this require writing an app or
is there an automated way of doing
this?
Yes, both of these options would require writing an app or buying an app. If you write your own app then you'll need to find a third-party PDF library that supports retrieving data from form fields or extracting text from a PDF.
Disclaimer: I am affiliated with the makers of ByteScout PDF Extractor SDK tool
Just wanted to share some additional real-life scenarios for text data extraction from PDF:
Scanned image with no searchable text: should be processed by OCR engine (like free Tesseract from Google)
XFA forms: it is the subset of PDF which is supported mostly by Adobe tools. But the data can be extracted as XML data with low level PDF processing tools like iTextSharp or similar tools.
ZUGFeRD PDF files which are just PDF documents with the copy of a form data attached as XML file (which can be extracted with tools like this)
Text incorrectly encoded by some PDF generators (can be restored via OCR engine with some acceptable error rate though).
Using ItextSharp, do the following
using System;
using System.Configuration;
using System.Data.SqlClient;
using System.IO;
using System.Text;
using iTextSharp.text.pdf;
protected void BtnSubmit_Click(object sender, EventArgs e)
{
String FilePath = #"GetFilePath";
StringBuilder sb = new StringBuilder();
PdfReader reader = new PdfReader(FilePath);
PdfStamper myStamp = new PdfStamper(reader, new FileStream(FilePath + "_TMP", FileMode.Create));
AcroFields form = myStamp.AcroFields;
if (form.GetField("GetFieldIdFromPDF") != null)
sb.Append(form.GetField("GetFieldIdFromPDF").ToString());
}
I think you will have to write an application for this. This question talks about extracting data from PDF. After this you can export the data to excel format so that you can preserve the existing import format.
Look for information on "Scraping" the data from the PDF. I believe Adobe has some tools that allow you to do this for simple text but I've not used them.
Honestly though, I would try to do anything you can to get this data in a raw format from your vendor.

Storing PDFs in MS Access Database using Forms

I need to store PDF files in an Access database on a shared drive using a form. I figured out how to do this in tables (using the OLE Object field, then just drag-and-drop) but I would like to do this on a Form that has a Save button. Clicking the save button would store the file (not just a link) in the database. Any ideas on how to do this?
EDIT:
I am using Access 2003, and the DB will be stored on a share drive, so I'm not sure linking to the files will solve the problem.
We have several databases that contain 10's of thousands of documents (pdf, doc, jpg, ...), no problem at all. In Access, we use the following code to upload a binary object to a binary field:
Function LoadFileFromDisk(Bestand, Optional FileName As String = "")
Dim imgByte() As Byte
If FileName = "" Then FileName = strFileName
Open FileName For Binary Lock Read As #1
ReDim imgByte(1 To LOF(1))
Get #1, , imgByte
Close #1
If Not IsEmpty(imgByte) Then Bestand.Value = imgByte
End Function
In this case, Bestand is the field that contains the binary data.
We use MS SQL Server as a backend, but the same should work on an Access backend.
If you used the same concept but upsized to SQL Server- storing PDFs inside of an Image datatype (or varbinary(max)) then you could SEARCH INSIDE THE PDFs using Full Text Search.
I show that Microsoft says you can do this for any file type where you can register an IFILTER product.. and I just was at the Adobe website the other day and say that their Acrobat IFILTER is indeed FREE.
Maybe this will help: ACC2000: Reading, Storing, and Writing Binary Large Objects (BLOBs).
What they do: Read a file in chunks and add it to a blob using a VBA function.
A field of OLE Object, by default would use a Bound Object Frame on the form. Right click on it and you can Insert an object. It comes complete with browsing for the file. Double-click on the field and the actual document will open.
I recommend going with David's advice and link. Unless you have a need to transfer a single file and want all the PDF's included. Size and performance will be an issue.
If security is an issue and the Access file is the only control you have (You are unable to set security on the folder containing all the linked files.), then you would have to embed.