Solved

Loading Field of type 'OLE Object' in Picture control

Posted on 1998-09-01
12
221 Views
Last Modified: 2013-11-25
Hi Experts,

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

Thank you
0
Comment
Question by:marti
  • 6
  • 4
  • 2
12 Comments
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1432469
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.
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1432470
the picture is a BMP file.
0
 
LVL 2

Author Comment

by:marti
ID: 1432471
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?



0
 
LVL 14

Accepted Solution

by:
waty earned 200 total points
ID: 1432472
You can't do that.
You have first to save your field into a file and ther open this file using LoadPicture :

Use the following function to save the field to a file

Sub GetFileFromDB(BinaryField As Field, szFileName As String)
    ' *** Will retrieve an entire Binary field and write it to disk ***
   
    Dim NumChunks    As Long
    Dim TotalSize    As Long
    Dim RemChunk     As Integer
    Dim CurSize      As Integer
    Dim nChunkSize   As Long
    Dim nI           As Integer
    Dim nFile        As Integer
    Dim CurChunk     As String
   
    nChunkSize = 32000    ' Set size of chunk.
   
    ' *** Get field size.
    TotalSize = BinaryField.FieldSize()
    NumChunks = TotalSize \ nChunkSize   ' Set number of chunks.
   
    ' *** Set number of remaining bytes.
    RemChunk = TotalSize Mod nChunkSize
   
    ' *** Set starting size of chunk.
    CurSize = nChunkSize
    nFile = FreeFile ' Get free file number.
   
    Open szFileName For Binary As #nFile  ' Open the file.
    For nI = 0 To NumChunks
       If nI = NumChunks Then CurSize = RemChunk
       CurChunk = BinaryField.GetChunk(nI * nChunkSize, CurSize)
       Put #nFile, , CurChunk   ' Write chunk to file.
    Next
    Close nFile

End Sub

0
 
LVL 2

Author Comment

by:marti
ID: 1432473
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.
0
 
LVL 2

Author Comment

by:marti
ID: 1432474
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?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 14

Expert Comment

by:waty
ID: 1432475
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


0
 
LVL 2

Author Comment

by:marti
ID: 1432476
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?
0
 
LVL 14

Expert Comment

by:waty
ID: 1432477
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.
0
 
LVL 2

Author Comment

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

0
 
LVL 14

Expert Comment

by:waty
ID: 1432479
Yes.

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

Author Comment

by:marti
ID: 1432480
Thank you waty!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now