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 16361
Am i asking the wrong question in the wrong forum?
FishVal 2,653
Recognized Expert Specialist
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.
FishVal 2,653
Recognized Expert Specialist
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.
FishVal 2,653
Recognized Expert Specialist
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 JPG images in the blob. Well, it stores it but as a string of bytes:
'x0dx0fxffxa3......'
So, when reading back that information into my python environment, it seems that I need to translate the value back to the original binary format?
...
|
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 images, jpg images) to Microsoft SQL Server 2000
using Microsoft DTS.
On trying to perform this simple conversion I recieved the error "Need
to run the object to perform the operation - Exception Access
Violation" from Microsoft DTS and my table...
|
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 which maintains the
relationship between the BLOB loid and the identity that relates to it in
my user tables. So far so good.
When I RTFM obout psql it refers to the \lo_import, \lo_list, \lo_export
and \lo_unlink functions.
|
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. I
can do this individually for each graph but this does not help me as I need
both on the same JPEG. I thought I would try an export the form that
contains both but I am having trouble. (My VBA is self taught and a little
knowledge is...
|
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.
Problem is that access doesn't export the images when saving to HTML :(
The export to PDF solution isn't appropriate in this instance, is their a
third party print to html utility anywhere, or any other easy solution to
this problem?
| |
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 Documents section to load Blobs
into the Portal Database on SQL Server. When I upload small binary
documents everything works fine. However, when I try to upload larger files
with the same content/mime types as the smaller files I get a response...
|
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 to upload larger files
with the same content/mime types as the smaller files I get a response from
the Webserver stating that the page can not be found. I do not know the
limit of the file sizes (I know it choked on an 8 MG File) but I have...
|
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 images that represent almost any type of Accident.
Each crash record can be represented by one of those 50 images
(depending on the Crash Data).
I don't want to waste space by having each record have a BLOB field w/
|
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 that was using some ADO
and it would write a small part of the image correctly and then the
rest was a mess. I was told to check out the ADO and VB groups to see
if anyone knows of a solution for this.
Does anyone have any resources or examples...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |