Hi,
I am new on here, and had a newbie question that I am stumped with.
I am not new to access, but am new to VB.
I am trying to export BLOBs from a field called photo to external jpeg files. I have tried the MS kb 210486 and successfully got the import/export to work with a sample table, but only the first record. I do not wish to impost binary data to the database, it's already there. I simply wish to pick up the binary BLOB from the photo field and export it to an image file, autonaming it.
Here is a sample of my table.
IDnumber | Lastname | Firstname | Address | Photo |
----------------------------------------------------------------------------
12485881 | Simpson | Homer...... |12 Hills St| long binary data |
12335682 | Fernando | Manny.......| 1 Elm St | long binary data |...
I am trying to take all the BLOBs under the "photo" field and export them to jpgs using the IDnumber field as the filename.
I have cut the code down to the following as I do not need to import an image in, it is already there. After cutting it down this far, I am getting an ambiguous name: Copyfile. -
Option Explicit
-
Const BlockSize = 32768
-
-
'**************************************************************
-
' 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 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 BLOB", 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
-
-
'**************************************************************
-
' SUB: CopyFile
-
'
-
' PURPOSE:
-
' Demonstrates how to use ReadBLOB() and WriteBLOB().
-
'
-
' PREREQUISITES:
-
' A table called BLOB that contains an OLE Object field called
-
' Blob.
-
'
-
' ARGUMENTS:
-
' Source - The path and filename of the information to copy.
-
' Destination - The path and filename of the file to write
-
' the binary information to.
-
'
-
' EXAMPLE:
-
' CopyFile "c:\windows\winfile.hlp", "c:\windows\winfil_1.hlp"
-
'**************************************************************
-
Sub CopyFile(Destination As String)
-
Dim BytesWritten As Variant
-
Dim Msg As String
-
Dim db As DAO.Database
-
Dim T As DAO.Recordset
-
-
' Open the University table.
-
Set db = CurrentDb()
-
Set T = db.OpenRecordset("University", dbOpenTable)
-
-
' Create a new record and move to it.
-
T.AddNew
-
T.Update
-
T.MoveLast
-
-
-
BytesWritten = WriteBLOB(T, "Photo", Destination)
-
-
Msg = "Finished writing """ & Destination & """"
-
Msg = Msg & Chr$(13) & ".. " & BytesWritten & " bytes written."
-
MsgBox Msg, 64, "Copy File"
-
End Sub
-
Using Access 2003, the db format is Access 2000.
5 16276
Am i asking the wrong question in the wrong forum?
Hi,
I am new on here, and had a newbie question that I am stumped with.
I am not new to access, but am new to VB.
I am trying to export BLOBs from a field called photo to external jpeg files. I have tried the MS kb 210486 and successfully got the import/export to work with a sample table, but only the first record. I do not wish to impost binary data to the database, it's already there. I simply wish to pick up the binary BLOB from the photo field and export it to an image file, autonaming it.
Here is a sample of my table.
IDnumber | Lastname | Firstname | Address | Photo |
----------------------------------------------------------------------------
12485881 | Simpson | Homer...... |12 Hills St| long binary data |
12335682 | Fernando | Manny.......| 1 Elm St | long binary data |...
I am trying to take all the BLOBs under the "photo" field and export them to jpgs using the IDnumber field as the filename.
I have cut the code down to the following as I do not need to import an image in, it is already there. After cutting it down this far, I am getting an ambiguous name: Copyfile. -
Option Explicit
-
Const BlockSize = 32768
-
-
'**************************************************************
-
' 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 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 BLOB", 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
-
-
'**************************************************************
-
' SUB: CopyFile
-
'
-
' PURPOSE:
-
' Demonstrates how to use ReadBLOB() and WriteBLOB().
-
'
-
' PREREQUISITES:
-
' A table called BLOB that contains an OLE Object field called
-
' Blob.
-
'
-
' ARGUMENTS:
-
' Source - The path and filename of the information to copy.
-
' Destination - The path and filename of the file to write
-
' the binary information to.
-
'
-
' EXAMPLE:
-
' CopyFile "c:\windows\winfile.hlp", "c:\windows\winfil_1.hlp"
-
'**************************************************************
-
Sub CopyFile(Destination As String)
-
Dim BytesWritten As Variant
-
Dim Msg As String
-
Dim db As DAO.Database
-
Dim T As DAO.Recordset
-
-
' Open the University table.
-
Set db = CurrentDb()
-
Set T = db.OpenRecordset("University", dbOpenTable)
-
-
' Create a new record and move to it.
-
T.AddNew
-
T.Update
-
T.MoveLast
-
-
-
BytesWritten = WriteBLOB(T, "Photo", Destination)
-
-
Msg = "Finished writing """ & Destination & """"
-
Msg = Msg & Chr$(13) & ".. " & BytesWritten & " bytes written."
-
MsgBox Msg, 64, "Copy File"
-
End Sub
-
Using Access 2003, the db format is Access 2000.
Hi.
I'm pretty not sure that content of an OLE field is the same as that of file you've inserted to the field, unless you've inserted it with AppendChunk method.
Common sence. Access needs to store OLE wrapper together with raw data to open a record properly.
Hi.
I'm pretty not sure that content of an OLE field is the same as that of file you've inserted to the field, unless you've inserted it with AppendChunk method.
Common sence. Access needs to store OLE wrapper together with raw data to open a record properly.
I'm not understanding. I am using the sample code from MS, and trying to work it so that I can write an existing BLOB to a file, rather than import one first.
I'm not understanding. I am using the sample code from MS, and trying to work it so that I can write an existing BLOB to a file, rather than import one first.
Try to decrease BlockSize. I'm not sure that String type variable can contain 32k of data.
I've tested a similar code. It worked fine with BlockSize 512 bytes.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Raaijmakers, Vincent (GE Infrastructure) |
last post by:
It is the first time that I use blobs in mysql.
Please help me out here.....
Using MSSQLdb and python 2.3.4 I was surprised to see how my information was stored in the blob.
My goal is to store...
|
by: gary.scott |
last post by:
Aaaaaarrgghh ! (that's better)
I am trying to convert a field within my Oracle 9i Database that is of
type BLOB (but this BLOB may contain a combination of clobs/varchars or
images such as gif...
|
by: Howard Lowndes |
last post by:
My situation is that I am interacting PHP 4.1.2 to PostgreSQL 7.2.2
I have no difficulty inserting and managing BLOBs into the Large Object
system table, and I have a user table called images...
|
by: David Lauberts |
last post by:
Hi
Wonder if someone has some words of wisdom.
I have a access 2002 form that contains 2 graph objects that overlay each
other and would like to export them as a JPEG to use in a presentation....
|
by: Chris Cox |
last post by:
I'm trying to put together a simple access database that will allow a friend
to maintain a simple database of products/pictures/prices, which he can then
export to html and upload to a website.
...
|
by: .Net Newbie |
last post by:
I am currently working with the C# version of the PortalSDK in a text editor
and have run across a bug that I need to resolve in order for my app to
function properly. Basically, I'm using the...
|
by: .Net Newbie |
last post by:
Basically, I'm using the Documents section of the PortalCSSDK to load Blobs
into the Portal Database on SQL Server. When I upload small binary
documents everything works fine. However, when I try...
|
by: meyvn77 |
last post by:
Hello -
I am looking for the best way to store images in a Access DB.
My Idea -
I have a table with 150,000 records. These recoreds represent a Crash
(Traffic Accident).
I have 50 different...
|
by: Jerry |
last post by:
Hello!
I have a SQL Server database with gif images stored in a nText field as
binary. I've been asked to export these images to actual gif files
(about 250 of them). I found a stored procedure...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |