Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add jpgs from VB6 front end to access backend 1

Status
Not open for further replies.

DOA

Instructor
Aug 16, 2001
29
US
I have a Access 2000 backend and it has 5 field
Id-Number
Company_Name - Text
Description - Text
Art Comments - Text
Graphic - OLE Object

I have a front end in VB6 that can look at all of the field including the graphics. I have it bound using ADO, I think. I used the wizard data connection and Have the text connected to other text and the graphic on the db connectted to a OLE (OLE1)

I would like to know if you can copy the picture, let say from the web and then add the pictures to the database through the front end.

Any ideas?
Any help..

I have created this in access but it is slow and some of the images are getting lost.
 
Most of the solutions you might find for this problem will involve BLOBS (binary large objects), together with GetChunk and AppendChunk for reading and writing the them. They generally require an intermediary disk file.

But here is a different method, which I've just come up with. For the purposes of the example you'll need an database with containing a table with a field called BLOB, that datatype of which is set to OLE Object. You'll also want a form with two picture boxes on it. Picturebox 1 should contain a picture, picturebox2 should be blank. And you'll want a command button. Then just drop in the following code:
[tt]
Private Sub Command1_Click()

SaveImage Picture1.Picture, DataEnvironment1.rsCommand1 ' Obviously put your own recordset in here
Set Picture2.Picture = GetImage(DataEnvironment1.rsCommand1) ' Obviously put your own recordset in here

End Sub

' Save specified picture into column BLOB of specified recordset
Private Function SaveImage(picPicture As Picture, rsImage As ADODB.Recordset)
Dim pb As PropertyBag
Dim BinaryData() As Byte
Dim mstream As ADODB.Stream

Set pb = New PropertyBag
Set mstream = New ADODB.Stream
rsImage.Open
rsImage.AddNew

pb.WriteProperty "Picture", picPicture
BinaryData = pb.Contents
mstream.Type = adTypeBinary
mstream.Open
mstream.Write BinaryData
mstream.Position = 0 ' Back to beginning of stream
rsImage("BLOB").Value = mstream.Read
rsImage.Update
rsImage.Close
End Function

Private Function GetImage(rsImage As ADODB.Recordset) As Picture
Dim pBinaryData As PropertyBag
Dim BinaryData() As Byte
Dim mstream As ADODB.Stream

Set pb = New PropertyBag
Set mstream = New ADODB.Stream

rsImage.Open
rsImage.MoveFirst

pb.WriteProperty "Picture", picPicture
BinaryData = pb.Contents
mstream.Type = adTypeBinary
mstream.Open
mstream.Write rsImage("BLOB").Value
mstream.Position = 0 ' Back to beginning of stream
BinaryData = mstream.Read
pb.Contents = BinaryData
rsImage.Close
Set GetImage = pb.ReadProperty("Picture")
End Function
 
Saving a bitmap image from VB6 to MsAccess.

I believe STRONGM's solution to DOA's 'Add jpgs from VB6 front end to access backend' is also the answer to my problem. My problem is how to save a bitmap image (BLOBS)from VB6 to Access. The only thing is I can't make STRONGM's solution to work. I can't figure out how exactly I can save the image to MsAccess. I would GREATLY APPRECIATE if anybody could email me a small VB project showing how it could be done.

Thanks a lot!!!
sabinojr
gannysabinojr@hotmail.com
 
As far as I can remember the above code and descriptive text contains all the info. What problem are you having?

Note that my code is merely an alternative to the standard GetChunk/AppendChunk technique, and relies on the fact that a StdPicture object is persistable.
 
STRONGM: My problem is how to save a bitmap image to MsAccess from VB6 without using the DataEnvironment. Would greatly appreciate if you could provide the complete code.

Thanks!

sabinojr
 
Ok...Requirements for the example stand: A form with two pictureboxes, one of which has a picture assigend to it, the other blank; one commmand button. You'll also need a database with a table called DataTable in it, which has one field in it called BLOB which is defined as an OLE object.

[tt]
Option Explicit
Private Sub Command1_Click()
Dim adoConnection As ADODB.Connection
Dim adoCommand As ADODB.Command
Dim adoRecordset As ADODB.Recordset

Set adoRecordset = New ADODB.Recordset

With adoRecordset
.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\demo.mdb;Persist Security Info=False"
.Source = "select BLOB from DemoTable"
.CursorType = adOpenDynamic
End With

SaveImage Picture1.Picture, adoRecordset
Set Picture2.Picture = GetImage(adoRecordset)

End Sub

' Save specified picture into column BLOB of specified recordset
Private Function SaveImage(picPicture As Picture, rsImage As ADODB.Recordset)
Dim pb As PropertyBag
Dim BinaryData() As Byte
Dim mstream As ADODB.Stream

Set pb = New PropertyBag
Set mstream = New ADODB.Stream
rsImage.Open
rsImage.AddNew

pb.WriteProperty "Picture", picPicture
BinaryData = pb.Contents
mstream.Type = adTypeBinary
mstream.Open
mstream.Write BinaryData
mstream.Position = 0 ' Back to beginning of stream
rsImage("BLOB").Value = mstream.Read
rsImage.Update
rsImage.Close
End Function

Private Function GetImage(rsImage As ADODB.Recordset) As Picture
Dim pb As PropertyBag
Dim BinaryData() As Byte
Dim mstream As ADODB.Stream
Dim picPicture As Picture

Set pb = New PropertyBag
Set mstream = New ADODB.Stream

rsImage.Open
rsImage.MoveFirst

pb.WriteProperty "Picture", picPicture
BinaryData = pb.Contents
mstream.Type = adTypeBinary
mstream.Open
mstream.Write rsImage("BLOB").Value
mstream.Position = 0 ' Back to beginning of stream
BinaryData = mstream.Read
pb.Contents = BinaryData
rsImage.Close
Set GetImage = pb.ReadProperty("Picture")
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top