Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Epi suite 5.0 MDB database with picture

Posted on 2002-05-15
7
371 Views
Last Modified: 2007-12-19
We had a software for our card picture production that was epi suite 5.0, we recently return our renting of that software after i made the exportation of all the picture.  But the problem is that if the database have more than one person of the same last name the exportation will do only the firts person having that lastname.  (To activate that software we need a special parallele keys).  So i identify, the table of the access mdb files that are suposed to included the image data.  That table have a fields whith binary data, (blob).  How can i view the picture.  I see the picture size on another field and i know there's all in jpg format.


I can send you an example of the database if you want!
0
Comment
Question by:dominic5
  • 5
  • 2
7 Comments
 
LVL 14

Expert Comment

by:mgrattan
ID: 7014090
The following code can be copied and then pasted into a new code module in Access.  You can then use the WriteBlob function to copy the objects in the binary data field of your table onto your hard drive.

Const BlockSize = 32768

'**************************************************************
      ' FUNCTION: ReadBLOB()
      '
      ' PURPOSE:
      '   Reads a BLOB from a disk file and stores the contents in the
      '   specified table and field.
      '
      ' PREREQUISITES:
      '   The specified table with the OLE object field to contain the
      '   binary data must be opened in Visual Basic code (Access Basic
      '   code in Microsoft Access 2.0 and earlier) and the correct record
      '   navigated to prior to calling the ReadBLOB() function.
      '
      ' ARGUMENTS:
      '   Source - The path and filename of the binary information
      '            to be read and stored.
      '   T      - The table object to store the data in.
      '   Field  - The OLE object field in table T to store the data in.
      '
      ' RETURN:
      '   The number of bytes read from the Source file.
      '**************************************************************
      Function ReadBLOB(Source As String, T As DAO.Recordset, _
      sField As String)
          Dim NumBlocks As Integer, SourceFile As Integer, i As Integer
          Dim FileLength As Long, LeftOver As Long
          Dim FileData As String
          Dim RetVal As Variant

          On Error GoTo Err_ReadBLOB

          ' Open the source file.
          SourceFile = FreeFile
          Open Source For Binary Access Read As SourceFile

          ' Get the length of the file.
          FileLength = LOF(SourceFile)
          If FileLength = 0 Then
              ReadBLOB = 0
              Exit Function
          End If

          ' Calculate the number of blocks to read and leftover bytes.
          NumBlocks = FileLength \ BlockSize
          LeftOver = FileLength Mod BlockSize

          ' SysCmd is used to manipulate status bar meter.
          RetVal = SysCmd(acSysCmdInitMeter, "Reading photo...", _
                   FileLength \ 1000)

          ' Put first record in edit mode.
          'T.MoveFirst
          'T.Edit

          ' Read the leftover data, writing it to the table.
          FileData = String$(LeftOver, 32)
          Get SourceFile, , FileData
          T(sField).AppendChunk (FileData)

          RetVal = SysCmd(acSysCmdUpdateMeter, LeftOver / 1000)

          ' Read the remaining blocks of data, writing them to the table.
          FileData = String$(BlockSize, 32)
          For i = 1 To NumBlocks
              Get SourceFile, , FileData
              T(sField).AppendChunk (FileData)

              RetVal = SysCmd(acSysCmdUpdateMeter, BlockSize * i / 1000)
          Next i

          ' Update the record and terminate function.
          T.Update
          RetVal = SysCmd(acSysCmdRemoveMeter)
          Close SourceFile
          ReadBLOB = FileLength
          Exit Function

Err_ReadBLOB:
          ReadBLOB = -Err
          Exit Function

      End Function

      '**************************************************************
      ' FUNCTION: WriteBLOB()
      '
      ' PURPOSE:
      '   Writes BLOB information stored in the specified table and field
      '   to the specified disk file.
      '
      ' PREREQUISITES:
      '   The specified table with the OLE object field containing the
      '   binary data must be opened in Visual Basic code (Access Basic
      '   code in Microsoft Access 2.0 or earlier) and the correct
      '   record navigated to prior to calling the WriteBLOB() function.
      '
      ' ARGUMENTS:
      '   T           - The table object containing the binary information.
      '   sField      - The OLE object field in table T containing the
      '                 binary information to write.
      '   Destination - The path and filename to write the binary
      '                 information to.
      '
      ' RETURN:
      '   The number of bytes written to the destination file.
      '**************************************************************
      Function WriteBLOB(T As DAO.Recordset, sField As String, _
      Destination As String)
          Dim NumBlocks As Integer, DestFile As Integer, i As Integer
          Dim FileLength As Long, LeftOver As Long
          Dim FileData As String
          Dim RetVal As Variant

          On Error GoTo Err_WriteBLOB

          ' Get the size of the field.
          FileLength = T(sField).FieldSize()
          If FileLength = 0 Then
              WriteBLOB = 0
              Exit Function
          End If

          ' Calculate number of blocks to write and leftover bytes.
          NumBlocks = FileLength \ BlockSize
          LeftOver = FileLength Mod BlockSize

          ' Remove any existing destination file.
          DestFile = FreeFile
          Open Destination For Output As DestFile
          Close DestFile

          ' Open the destination file.
          Open Destination For Binary As DestFile

          ' SysCmd is used to manipulate the status bar meter.
          RetVal = SysCmd(acSysCmdInitMeter, _
          "Writing " & T!EmpID & ".jpg", FileLength / 1000)

          ' Write the leftover data to the output file.
          FileData = T(sField).GetChunk(0, LeftOver)
          Put DestFile, , FileData

          ' Update the status bar meter.
          RetVal = SysCmd(acSysCmdUpdateMeter, LeftOver / 1000)

          ' Write the remaining blocks of data to the output file.
          For i = 1 To NumBlocks
              ' Reads a chunk and writes it to output file.
              FileData = T(sField).GetChunk((i - 1) * BlockSize _
                 + LeftOver, BlockSize)
              Put DestFile, , FileData

              RetVal = SysCmd(acSysCmdUpdateMeter, _
              ((i - 1) * BlockSize + LeftOver) / 1000)
          Next i

          ' Terminates function
          RetVal = SysCmd(acSysCmdRemoveMeter)
          Close DestFile
          WriteBLOB = FileLength
          Exit Function

Err_WriteBLOB:
          WriteBLOB = -Err
          Exit Function

      End Function
0
 

Author Comment

by:dominic5
ID: 7016135
to mgrattan

May be, i'm not skill enough, but i try to includes that lines of code on the module section and i named that module1

But may be i didnt know how to call the fuction?

I made a button on a form  wiht an execution code on a click = (like) do function (module1)


Can you help me a little bit more

Thank you

Dominic
0
 
LVL 14

Expert Comment

by:mgrattan
ID: 7016482
When you place a button on the form you just need to call the function from the button click event.  Here are the steps:

1.  In design view, double-click on the button or right click and choose Properties to bring up the property sheet.
2.  Click the Event tab and locate the On Click event.  Double-click in the On Click field to select [Event Procedure] and then click the Build button (it has three dots on it) to open the code module for the event.
3.  Place the following code in the event procedure:


          Dim BytesWritten As Variant
          Dim db As DAO.Database
          Dim T As DAO.Recordset
          Dim Destination As String

          ' Open the table containing BLOB data
          Set db = CurrentDb()
          Set T = db.OpenRecordset("<table name>", dbOpenTable)

          T.MoveFirst
          Do Until T.EOF
              BytesWritten = WriteBLOB(T, "<Field Name>", Destination)
              T.MoveNext
          Loop

You will notice in the WriteBlob function there is a reference to "T!EmpID".  You will need to replace this with "T(sField)" so the function will use the field name passed to it.  In the sample code above, make sure you replace <table name> and <field name> with the appropriate table and field names that contain your BLOB data.

You can get creative with the Destination parameter of the above code and pull it from your table.  Let's say you have a field called EmployeeID; you can modify the Do Loop like this:

          Do Until T.EOF
              Destination = "c:\MyFiles\" & T!EmpID & ".jpg"
              BytesWritten = WriteBLOB(T, "<Field Name>", Destination)
              T.MoveNext
          Loop

Let me know if you have further questions.

Mike.
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

Author Comment

by:dominic5
ID: 7019785
Tank you for your previoust answer, but it still not working good.

The processus stop as soon as i execute it.

So i, put a stop process to look on the variable

and the problem comes from the blocksize =0

I put the lines blocksize = 5000

after that the processus work all files are writed, but the files are not readable from a program like acdsee or anyone else.

Do you have another idea


Thank you

Dominic5
0
 
LVL 14

Expert Comment

by:mgrattan
ID: 7019979
You can send a copy of the database to me:
mikeg at taproduce dot com.

I can take a look at it during the week and see what I can do.

Mike.
0
 
LVL 14

Expert Comment

by:mgrattan
ID: 7019985
BTW, I don't see anything in the code that explicitly sets Blocksize to 0.  It starts out as a Constant that is set to 32768.

Anyway, once I see your database and step through the code I'll see what's going on.
0
 
LVL 14

Accepted Solution

by:
mgrattan earned 500 total points
ID: 7040274
As I mentioned in the email I sent to you, the OLE field that apparently stores your images does not seem to contain complete files.  It looks like possibly the images are split into multiple records; extracting image files from multiple records will require that the WriteBlob function is executed from within a Do Loop while iterating through the table's RecordSet object using the FindNext method to locate the necessary records for the parts of the image that need to be combined.  The code that I sent to you appears to be working fine otherwise.

Regards,
Mike
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question