Displaying Long Binary Data in a Report

G

Guest

I have an Access 2000 database (TrainingClasses.MDB) containing a table (ClassHistory) with an OLE Object field (StudentSign). I have written a VB.NET application, which populates ClassHistory - the StudentSign field is being populated with students' signatures (captured from a PDA device). My application can read/write the signatures with no problems (they are originally captured as bitmap images, then my application stores them into the StudentSign field). When I am looking at the table via datasheet view, the StudentSign field shows "Long Binary Data". I have noticed that if I manually insert a .BMP file (through the Access Insert->Object pulldown menu), the field will display "Bitmap Image" rather than "Long Binary Data"

I have created a simple report in Access to just display all the fields from ClassHistory. However, the StudentSign field displays nothing for those bitmap signatures which were added via my application. It displays the bitmap signature just fine for a record where I manually inserted the bitmap image through Access

Does this issue just boil down to an inherant problem between populating the data through my program (which is a process not as simple as just grabbing a .BMP file and sticking it into the field - I have to use an array into which the bitmap image is loaded, then store that into the field - fairly complicated process), and Access not being able to decipher the data that my app has loaded into the OLE Object field? As best I can tell, there is no way to programmatically insert a .BMP image into an Access OLE Object field, and Access still see this as a "Bitmap Image" (as it does when I manually insert a .BMP image through Access)

Bottom line - am I going to have to just code a report viewer in my VB.NET application, rather than trying to use Access' report feature

- Thanks

JRD
 
L

Larry Linson

Perhaps downloading and reading the article and examining the sample
databases will help.

The sample imaging databases at http://accdevel.tripod.com illustrate three
approaches to handling images in Access, and the download includes an
article discussing considerations in choosing an approach. Two of the
approaches do not use OLE Objects and, thus, avoid the database bloat, and
some other problems, associated with images in OLE Objects.

If you are printing the images in reports, to avoid memory leakage, you
should also see MVP Stephen Lebans' http://www.lebans.com/printfailures.htm.
PrintFailure.zip is an Access97 MDB containing a report that fails during
the Access formatting process prior to being spooled to the Printer Driver.
This MDB also contains code showing how to convert the contents of the Image
control to a Bitmap file prior to printing. This helps alleviate the "Out of
Memory" error that can popup when printing image intensive reports.

Larry Linson
Microsoft Access MVP

John Dougherty said:
I have an Access 2000 database (TrainingClasses.MDB) containing a table
(ClassHistory) with an OLE Object field (StudentSign). I have written a
VB.NET application, which populates ClassHistory - the StudentSign field is
being populated with students' signatures (captured from a PDA device). My
application can read/write the signatures with no problems (they are
originally captured as bitmap images, then my application stores them into
the StudentSign field). When I am looking at the table via datasheet view,
the StudentSign field shows "Long Binary Data". I have noticed that if I
manually insert a .BMP file (through the Access Insert->Object pulldown
menu), the field will display "Bitmap Image" rather than "Long Binary Data".
I have created a simple report in Access to just display all the fields
from ClassHistory. However, the StudentSign field displays nothing for
those bitmap signatures which were added via my application. It displays
the bitmap signature just fine for a record where I manually inserted the
bitmap image through Access.
Does this issue just boil down to an inherant problem between populating
the data through my program (which is a process not as simple as just
grabbing a .BMP file and sticking it into the field - I have to use an array
into which the bitmap image is loaded, then store that into the field -
fairly complicated process), and Access not being able to decipher the data
that my app has loaded into the OLE Object field? As best I can tell, there
is no way to programmatically insert a .BMP image into an Access OLE Object
field, and Access still see this as a "Bitmap Image" (as it does when I
manually insert a .BMP image through Access).
Bottom line - am I going to have to just code a report viewer in my VB.NET
application, rather than trying to use Access' report feature?
 
S

Stephen Lebans

John you are using two completely different methods to store data in
your Long Binary field.

1) Manually, in Acess you are inserting the BMP file as an OLE Object.
THe Long Binary field now contains OLE object data.

2) Programmatically inserting Byte data into a Long Binary field. The
Long Binary field does NOT contain OLE object data but simply your raw
binary data.

You should not mix the two data types. While you can programmatically
insert Images as OLE objects I would reccomend against it unless you
will only require a couple of Images.

If the raw Binary data is an exact copy of the original BMP file then
you have several options available to enable you to display the data in
a Report's standard Image control(not one of the OLE Frame controls!).

1)
In the Print event of the Detail section save the contents of the Binary
field to a temp disk file named say "1.BMP".
Set the Image control's Picture property to "1.BMP"

2) Rather than saving a Bitmap file, save a DIB(Device Independant
Bitmap) instead. Then you could easily, without having to save to a TEMP
disk file, load the DIB directly into the PictureData propery of the
Image control.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.


John Dougherty said:
I have an Access 2000 database (TrainingClasses.MDB) containing a
table (ClassHistory) with an OLE Object field (StudentSign). I have
written a VB.NET application, which populates ClassHistory - the
StudentSign field is being populated with students' signatures (captured
from a PDA device). My application can read/write the signatures with
no problems (they are originally captured as bitmap images, then my
application stores them into the StudentSign field). When I am looking
at the table via datasheet view, the StudentSign field shows "Long
Binary Data". I have noticed that if I manually insert a .BMP file
(through the Access Insert->Object pulldown menu), the field will
display "Bitmap Image" rather than "Long Binary Data".
I have created a simple report in Access to just display all the
fields from ClassHistory. However, the StudentSign field displays
nothing for those bitmap signatures which were added via my application.
It displays the bitmap signature just fine for a record where I manually
inserted the bitmap image through Access.
Does this issue just boil down to an inherant problem between
populating the data through my program (which is a process not as simple
as just grabbing a .BMP file and sticking it into the field - I have to
use an array into which the bitmap image is loaded, then store that into
the field - fairly complicated process), and Access not being able to
decipher the data that my app has loaded into the OLE Object field? As
best I can tell, there is no way to programmatically insert a .BMP image
into an Access OLE Object field, and Access still see this as a "Bitmap
Image" (as it does when I manually insert a .BMP image through Access).
Bottom line - am I going to have to just code a report viewer in my
VB.NET application, rather than trying to use Access' report feature?
 
G

Guest

Right, I understand about mixing the data - that is not what I wanted to have in the end, I was just doing some experimenting. So sure, I don't want the mix of data types

I have only coded actual VB applications in the past, and know very little about using VBA. Is there some example code to which you can direct me which would help in writing the necessary code in the Print event of the Detail section? I have actually started working on it, but am having problems accessing the data from my StudentSign field (the long binary data field). Here is the code I have so far

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer
Dim intFileNum As Intege

If Len(StudentSign) > 0 The
intFileNum = FreeFil
Open "c:\" & LTrim$(Str$(ClassHistory_ClassNumber)) & "-" & LTrim$(Str$(StudentNumber)) & ".bmp" For Binary Loc
Read Write As #intFileNu
Put #intFileNum, , StudentSig
Close #intFileNu
End I
End Su

Nothing ever shows up in StudentSign - it is always rendered as empty. What am I doing wrong there

Also, I have tried to drop a standard image control onto my report, but it only works if I select a pre-existing .BMP file. Otherwise, the control disappears if I do not select an existing .BMP file. Am I doing something wrong there

- Thanks

JRD
 
S

Stephen Lebans

Well John you have me completely mixed up again!<grin>
Do you want to:

1) Leave the Images as theu currently exist stored externally in their
own folder on your hard drive
or
2) Embedd an exact copy of the original Image directly within a table in
your MDB


Did you look at the sample code I pointed you to on my site for reading
/writing to a Long Binary field?
http://www.lebans.com/loadsavejpeg.htm
Just focus on the few lines of code that read/write the Binary field.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.


John Dougherty said:
Right, I understand about mixing the data - that is not what I wanted
to have in the end, I was just doing some experimenting. So sure, I
don't want the mix of data types.
I have only coded actual VB applications in the past, and know very
little about using VBA. Is there some example code to which you can
direct me which would help in writing the necessary code in the Print
event of the Detail section? I have actually started working on it, but
am having problems accessing the data from my StudentSign field (the
long binary data field). Here is the code I have so far:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
Dim intFileNum As Integer

If Len(StudentSign) > 0 Then
intFileNum = FreeFile
Open "c:\" & LTrim$(Str$(ClassHistory_ClassNumber)) & "-" &
LTrim$(Str$(StudentNumber)) & ".bmp" For Binary Lock
Read Write As #intFileNum
Put #intFileNum, , StudentSign
Close #intFileNum
End If
End Sub

Nothing ever shows up in StudentSign - it is always rendered as empty. What am I doing wrong there?

Also, I have tried to drop a standard image control onto my report,
but it only works if I select a pre-existing .BMP file. Otherwise, the
control disappears if I do not select an existing .BMP file. Am I doing
something wrong there?
 
G

Guest

Thanks for your help Stephen (what I wanted to do is leave exact copies of the .BMP files embedded in my Access database, since I must transfer the captured signatures back-and-forth between a desktop and a handheld - I didn't want to have to transfer all those individual .BMP files around, just one Access database)

I looked at your examples, as well as my original VB.NET application which displays the OLE Object field, and here is what I ended up with, which works just fine (this the code in my Access report - "StudentSign" is my OLE Object field - "Image42" is my Image control on the report)

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer
Dim intFileNum As Intege
Dim aryImgData() As Byt
Dim varBMPFile As Varian

If IsNull(Me.StudentSign) = False The
varBMPFile = Me.StudentSig
Image42.Visible = Tru
intFileNum = FreeFil
Open "c:\usersign.bmp" For Binary Lock Read Write As #intFileNu
ReDim aryImgData(Len(varBMPFile) - 1
aryImgData = varBMPFil
Put #intFileNum, , aryImgDat
Close #intFileNu
Image42.Picture = "c:\usersign.bmp
Els
Image42.Visible = Fals
End I
End Su

I am just reusing this "usersign.bmp" temporary file over and over - then in the Report_Close method, I kill the file. This does the trick - thanks again

- JRD
 
S

Stephen Lebans

Gald you were able to derive a solution. I have run into problems before
with fixed temp files. If this app is for widespread produciton release
I would encourage you to use the Temp Path and Temp File API's to
generate proper windows temp files.

--
HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.


John Dougherty said:
Thanks for your help Stephen (what I wanted to do is leave exact
copies of the .BMP files embedded in my Access database, since I must
transfer the captured signatures back-and-forth between a desktop and a
handheld - I didn't want to have to transfer all those individual .BMP
files around, just one Access database)!
I looked at your examples, as well as my original VB.NET application
which displays the OLE Object field, and here is what I ended up with,
which works just fine (this the code in my Access report - "StudentSign"
is my OLE Object field - "Image42" is my Image control on the report):
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
Dim intFileNum As Integer
Dim aryImgData() As Byte
Dim varBMPFile As Variant

If IsNull(Me.StudentSign) = False Then
varBMPFile = Me.StudentSign
Image42.Visible = True
intFileNum = FreeFile
Open "c:\usersign.bmp" For Binary Lock Read Write As #intFileNum
ReDim aryImgData(Len(varBMPFile) - 1)
aryImgData = varBMPFile
Put #intFileNum, , aryImgData
Close #intFileNum
Image42.Picture = "c:\usersign.bmp"
Else
Image42.Visible = False
End If
End Sub

I am just reusing this "usersign.bmp" temporary file over and over -
then in the Report_Close method, I kill the file. This does the trick -
thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top