Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening and printing document in Blob file

Status
Not open for further replies.

jlockley

Technical User
Nov 28, 2001
1,522
US
Is there a way to program a button on a form to print a document in the blob file? (Ie, open and print the document?)
Alternately: A button to save documents I choose from blob files into a folder with incrementally increasing names (to be browsed later - names like doc1 doc2 doc3 would be fine.)

Much appreciated. JLL
 
jlockley,

Here's one way to do it:

Code:
uses "shell32.dll"
   ShellExecute( hwnd clong, lpOperation cptr,
                 lpFile cptr, lpParameters cptr,
                 lpDirectory cptr, nShowCmd clong ) clong
                 [stdcall "ShellExecuteA"]
endUses

method pushButton(var eventInfo Event)
var
   binDocData   Binary            ; Holds document data
   astrFiles    Array[] String    ; List of documents
   fs           FileSystem        ; Allows file saving
   liResult     Longint           ; ShellExecute result
   siDocCount   SmallInt          ; # of DOC files
   strDocName   String            ; Document Filename
   tcDocTable   TCursor           ; Pointer to BLOB data
endVar

const
   BLOB_TABLE = ":work:blobdemo"
   DOC_FOLDER = "c:\\temp\\"
endConst


   if not tcDocTable.open( BLOB_TABLE ) then
      errorShow( "Can't Open " + BLOB_TABLE,
                 "Use [>>] for more details." )
   else

      ; First, determine the target filename
      fs.enumFileList( DOC_FOLDER + "*.doc", astrFiles )
      astrFiles.view()
      siDocCount = astrFiles.size()
      strDocName = DOC_FOLDER + "Doc" +
                   String( siDocCount + 1 ) +
                   ".doc"

      ; Now, write the binary data to the file
      binDocData = tcDocTable."BlobData"
      binDocData.writeToFile( strDocName )

      ; Finally, print the document
      ShellExecute( 0, "print", strDocName, "", "", 3 )

   endIf

   ; Note: Always explicitly close TCursors
   if tcDocTable.isAssigned() then
      tcDocTable.close()
   endIf

endMethod

You'll note that this assumes your BLOB data is stored in a field called (strangely) BlobData.

Hope this helps...

-- Lance
 
Whoops, I accidentally forgot to remove a line of debugging code. You can delete the following line:

Code:
      astrFiles.view()

I was using it to make sure that my quick and dirty approach for incrementing the filename worked and forgot to remove it before posting.

Sorry...

-- Lance
 
I am doing something wrong. I have it entered under pushbutton - here the changed version

method pushButton(var eventInfo Event)

var
binDocData Binary ; Holds document data
astrFiles Array[] String ; List of documents
fs FileSystem ; Allows file saving
liResult Longint ; ShellExecute result
siDocCount SmallInt ; # of DOC files
strDocName String ; Document Filename
tcDocTable TCursor ; Pointer to BLOB data
endVar

const
BLOB_TABLE = ":schsearch:search1"
DOC_FOLDER = "c:\\temp\\"
endConst


if not tcDocTable.open( BLOB_TABLE ) then
errorShow( "Can't Open " + BLOB_TABLE,
"Use [>>] for more details." )
else

; First, determine the target filename
fs.enumFileList( DOC_FOLDER + "*.doc", astrFiles )
siDocCount = astrFiles.size()
strDocName = DOC_FOLDER + "Doc" +
String( siDocCount + 1 ) +
".doc"

; Now, write the binary data to the file
binDocData = tcDocTable."Resume"
binDocData.writeToFile( strDocName )

; Finally, print the document
ShellExecute( 0, "print", strDocName, "", "", 3 )

endIf

; Note: Always explicitly close TCursors
if tcDocTable.isAssigned() then
tcDocTable.close()
endIf

endMethod

schsearch is the alias (for sous chef search) and search1 is the Database (search1.mb would be the blob file).

Error is can't change OLE to binary. My bad for sure, but what? Thanks a lot, by the way. I am not trying to figure out what I am writing. Some makes sense.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top