|
Question : Need algorithm for printing files of all types from Access
|
|
I am working on an Access 2002 application where I need to print out a report with all information in the database for a given master record or set of records. This includes hyperlinked documents. I have ascertained the following through reading and experimenting: 1. Text documents can be printed from access thru the getobject function, which will load and print the document without you needing to specify the application to do this if the file type has been associated with that application through windows. 2. On our computers, perhaps because most of us here do not have specific applications for viewing or editing images, when getobject is used on an image file it will fail because no application is associated. (when I actually open an image file such as a jpeg, Microsoft Photo Editor displays the image). This presents no problem because I can bring any image into an Image box in MS Access and then print it from there and this is the approach I will be using. 3. Because I will actually be printing to Adobe Acrobat Writer, any pdf's will not actually printed, but I have received information on combining pdfs so my plan is to actually print a number of pdfs and then combine them into the final report thru Acrobat Writer. 4. Textfiles unassociated with an application will be printed using getobject with WordPad being the application. 5. I have already learned how to successfully read the Windows Registry, programmatically as well as manually.
WHICH NOW LEAVES the question I need answered, or at least direction as to where to find the answer:
What approach do I use to, reading the registry, direct a document to the appropriate method for printing, be it using getobject, linking with an image box, using getobject with wordpad, etc.
I have looked at the values for the various subkeys of HKEY_CLASSES_ROOT. For images, I can look for the PerceivedType value and see if it is equal to image. I believe I can do this for some textfiles. However, some file types associated with applications, such as .doc files, do not have a PerceivedType value, but do have the application as the default value for the subkey. But other filetypes have the default value populate, such as, on my system, .sql files showing sql_auto_file as the value (though this type of file also has a PerceivedType value, which is "text".
In otherwords, I am confused as to what the rules are for determining how to handle a file based on its HKEY_CLASSES_ROOT Registry entries. I need to understand these rules in order to automate the printing of all possible linked documents with the report I need to generate. Can anyone here help me?
sjl
|
|
Answer : Need algorithm for printing files of all types from Access
|
|
You can use ShellExecute to perform operations on any file if its extension is registered to an application, like .pdf to Acrobat or .doc to Word. Its a lot easier than going through all you did to identify the file type and its associated exe. Pointers to the articles needed to implement a solution for your problem are below, located at Dev Ashish's MVP site.
Search for a File http://www.mvps.org/access/api/api0006.htm Start Registered Applications with ShellExecute http://www.mvps.org/access/api/api0018.htm Return Long or Short File Names http://www.mvps.org/access/api/api0020.htm Find the Associated EXEs file path http://www.mvps.org/access/api/api0023.htm
I used a combination of these, with a little alteration in the Shell Execute wrapper to allow the calling function to pass an operation, such as "open" or "print" so that the application knows what to do with the file without intervention. I'd put that here, but he states the code is free to use only in an application, without alteration, and cannot be otherwise distributed. I wouldn't want to offend.
On a tangent, the following function allows you to print via automation any .pdf files on any computer on which the free Adobe Acrobat Reader has been installed. Again, I used alterations of the API calls above to locate the file on the machine.
Public Function PrintPDFForms(prtFileName As String, prtDrive As String) Dim AcrApp As Object Dim acrDoc As Object Dim acrPDDoc As Object Dim ret As Long Dim lngPage As Long
Set AcrApp = CreateObject("AcroExch.App") 'ret = AcrApp.Show() uncomment if you want to see the application window. Set acrDoc = CreateObject("AcroExch.AVDoc") acrDoc.Open fReturnFilePath(prtFileName, prtDrive), "PDF Print" Set acrPDDoc = acrDoc.GetPDDoc lngPages = acrPDDoc.GetNumPages ret = acrDoc.PrintPages(0, lngPages - 1, 1, True, True) Set acrDoc = Nothing Set acrPDDoc = Nothing AcrApp.CloseAllDocs AcrApp.Exit Set AcrApp = Nothing
End Function Hope it helps.
|
|
|
|