Click to See Complete Forum and Search --> : Saving a Bitmap,Gif or JPEG Image to an Access 2000 Database
Judgey
March 26th, 2001, 03:34 AM
Can somebody help me with this one,
How do you save the contents of the Image Control as an embedded image in an Access 2000 database table, I've tried all weekend and just cannot work it out ?
help !
Adhi Sheshu
March 26th, 2001, 04:33 AM
using the ado objects appendchunk method
for example:
strfilename is jpg file name
flddestination is field in the database
Function CopyLargeField(strfilename As String, fldDestination As Field)
Dim strchunk As String * 1024
Open strfilename For Input As #1
Do While Not EOF(1)
Input #1, strchunk
fldDestination.AppendChunk strchunk
strchunk = ""
Loop
Close #1
End Function
Its is available in the Msdn library in different way.
Judgey
March 26th, 2001, 04:39 AM
Is this not just saving the Filename of where the image is stored ?, I need to save the actual Image as an OLE object in the Database as various employees will be using this database and saving images, so one employee saves an image from his local drive, another employee needs to be able to open the image.
will this code achieve this as it looks like its just savinf strings?
Adhi Sheshu
March 26th, 2001, 05:06 AM
'Opening the access database connection
'Here the student database is a sample database
'two fields firstname and photo.
'the photo field data type being ole object
'while firstname is simple text
Private Sub Form_Load()
Set adoconn = New ADODB.Connection
With adoconn
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\Users\Sheshu\misc\db1.mdb"
.CursorLocation = adUseClient
.Open
End With
Set adors = New ADODB.Recordset
adors.CursorType = adOpenKeyset
adors.LockType = adLockOptimistic
adors.Open "students", adoconn, , , adCmdTable
End Sub
'In this click event getting the jpeg file path Private Sub Command1_Click()
With cdlgphoto
.CancelError = False
.Filter = "All Files [*.jpg]|*.jpg"
.ShowOpen
strfilename = .FileName
End With
End Sub
'Here inserting into the database
Private Sub Command2_Click()
On Error GoTo errhandler
adors.AddNew
adors.Fields!firstname = Text1.Text
CopyLargeField strfilename, adors!photo
adors.Update
Exit Sub
errhandler:
MsgBox Err.Number + Err.Description
End Sub
Function CopyLargeField(strfilename As String, fldDestination As Field)
Dim strchunk As String * 1024
Open strfilename For Input As #1
Do While Not EOF(1)
Input #1, strchunk
fldDestination.AppendChunk strchunk
strchunk = ""
Loop
Close #1
End Function
'The above code is inserting into database
'My problem was retrieving from database and showing on the UI.
E Jorgensen
March 28th, 2001, 09:43 AM
I would reserve a place on your server to store the image files. Access get big quickly and you might have performance issues later. We placed code in our form to display the image associated to an index. the pictures are stored ie: 1.bmp,2.bmp ect. when the form is opened it reives the picture or you can do the same thing in a report
Private Sub pic_number_GotFocus()
On Error GoTo ERRpic_number_GotFocus:
Image8.Picture = "C:\AAA\outside projects\" & [pic_number] & ".jpg"
Exit Sub
ERRpic_number_GotFocus: Image8.Picture = "C:\AAA\outside projects\" & 1009 & ".jpg"
End Sub
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.