Link to home
Start Free TrialLog in
Avatar of marti
marti

asked on

Loading Field of type 'OLE Object' in Picture control

Hi Experts,

How could I load the contents of field of type 'OLE Object' in Picture control.

Thank you
Avatar of a111a111a111
a111a111a111

Hi,
Try to start with this:

' ===========start==========

Option Explicit

Private Sub Command1_Click()
'Picture1.Picture.SetData
Clipboard.SetData Picture1.Picture
End Sub

'=========== end ========
than view the clipboard.
the picture is a BMP file.
Avatar of marti

ASKER

What I actually would like is to be able to store GIF or BMP files in a database table in field of type LongBinary or OLE Object. Later I would like to load that pictures data in picture control. Using directly:

    Set Picture1 = rs!picField

results in error. Any ideas?



ASKER CERTIFIED SOLUTION
Avatar of waty
waty
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of marti

ASKER

May be my question isn't clear enough. I would like to save a picture file (.BMP, .GIF) into a database field. And I would like to set the database field data to a picture control.
Avatar of marti

ASKER

That's a solution. May be not the one I've expected.
Do you mean the same path is followed for a bound picture control?
You have to save the field to a file. The Picture control don't know how to handle the OLE field.

marti, to save a file into a DB field, here is the function :

Function SaveFileToDB(Source As String, BynaryField As Field) As Integer
    ' *** Will save a file to a Binary field
   
   Dim nNumBlocks       As Integer
   Dim nFile            As Integer
   Dim nI               As Integer
   Dim nFileLen         As Long
   Dim nLeftOver        As Long
   Dim sFileData        As String
   Dim retval           As Variant
   Dim nBlockSize       As Long
   
   On Error GoTo Error_SaveFileToDB
   
   nBlockSize = 32000    ' Set size of chunk.
   
   ' *** Open the source file.
   nFile = FreeFile
   Open Source For Binary Access Read As nFile
   
   ' *** Get the length of the file.
   nFileLen = LOF(nFile)
   If nFileLen = 0 Then
      SaveFileToDB = 0
      Exit Function
   End If
   
   ' *** Calculate the number of blocks to read and nLeftOver bytes.
   nNumBlocks = nFileLen \ nBlockSize
   nLeftOver = nFileLen Mod nBlockSize
   
   ' *** Read the nLeftOver data, writing it to the table.
   sFileData = String$(nLeftOver, 32)
   Get nFile, , sFileData
   BynaryField.AppendChunk (sFileData)
   
   ' *** Read the remaining blocks of data, writing them to the table.
   sFileData = String$(nBlockSize, Chr$(32))
   For nI = 1 To nNumBlocks
      Get nFile, , sFileData
      BynaryField.AppendChunk (sFileData)
   Next
   Close #nFile
   SaveFileToDB = nFileLen
   
   Exit Function

Error_SaveFileToDB:
   SaveFileToDB = -Err
   Exit Function
End Function


Avatar of marti

ASKER

OK, so first you have to save a file in a binary field. And if you want to show that data in a picture you have to create a TEMP file and transfer the data back to it? And load that file into a picture?
Do you mean that if you have a Data control and picture control bound to it all these steps are taking place?
Yes. To enhance your speed, you should place the picture under a tab control, and loading the picture only if the user is currently viewing the picture.
Avatar of marti

ASKER

Do you mean that if you have a Data control and picture control bound to it all the above steps are taking place?

Yes.

NB : When I develop an application, I never use Data Control (I have developped around 50 applications in VB3 to VB5).
Avatar of marti

ASKER

Thank you waty!