Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB6: Moving pictures into a database.

Posted on 1998-09-30
4
Medium Priority
?
242 Views
Last Modified: 2010-04-30
I've got an app that uses a database.  This mdb file contains a directory that pretty much contains the path names to a bunch of images.  I am now to the point where I would like to simply embed each of these images into the mdb file itself.

How can I embed these files from code knowing only the path names leading to each file?

Lankford
0
Comment
Question by:lankford
[X]
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
  • 2
4 Comments
 
LVL 12

Expert Comment

by:mark2150
ID: 1437477
I'd imagine that you'ld have to use a MEMO data type and copy the image into it as a byte stream.

Only problem is that the images in the database aren't going to do you much good. You can't point to a field in a database in a LoadImage statement so if you want to *show* the images you'll have to pull the data back out of the database and recreate a file on disk as a temporary giz so you can then load the disk file back in to the picture control. This'll be slow as mud.

M
0
 

Author Comment

by:lankford
ID: 1437478
I've got an image control that will bind to this OLE Bindary data.  I don't have to worry about extraction, just insertion!
0
 
LVL 14

Accepted Solution

by:
waty earned 100 total points
ID: 1437479
Use the following function :

Function SaveFileToDB(Source As String, BynaryField As Field) As Integer
   ' *** Will save a file to a Binary field or memo 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
 

Author Comment

by:lankford
ID: 1437480
I found a much better way to do it.  Turns out that the control I am binding to the data source that displays the graphic will load the information into the database for you too. When loading the graphics, the current record then gets the binary data associated with that loaded file.  Pretty sweet and only one line of code.

I did try your code.  The image control would not read in the binary data and translate it into an image.  I do not know why and don't really have the time to find out.  

So, just to cut this short, I'll give you a C for an answer that may or may not have solved my problems.

Thank you for the reply.

Lankford
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

722 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