Storing BLOBs from directory

dobbs
11-03-2004, 01:02 PM
I have created a program that takes screen captures of a map image within the program and saves them as a .bmp to a desired path. What I would like to do is store these images in a MSAccess table using the OLE Object option. I know this is possible to do manually, but I need to have it programmatically add these images to the database. I want to add these images to a Crystal Reports .rpt template so I can have dynamic images. Has anyone done something similar to what I am requesting or can at least lead me in the right direction to get this accomplished. Thanks for everyone's time.

:confused:

dobbs
11-03-2004, 04:40 PM
I have been working on this some and this is what I have so far:


Option Explicit

Dim strImageName As String
Dim connMap As ADODB.Connection
Dim recMap As ADODB.Recordset
Dim BytMap() As Byte ' store pixel values for type .bmp image

Enum RecMove
MoveNext
MovePrevious
End Enum

Private Sub Form_Load()
'####Set for BMP Export####
Set connMap = New ADODB.Connection
Set recMap = New ADODB.Recordset
'connect to database
connMap.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\test\test.mdb;"
connMap.Open

recMap.Open "SELECT * FROM maps", adOpenDynamic, adLockOptimistic, adCmdText
'recMap.Open "SELECT * FROM maps", conn, adOpenDynamic, adLockOptimistic, adCmdText

' open connection to new database
connMap.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\test\test.mdb;"
connMap.Open

' open recordset
recMap.Open "SELECT * FROM maps", connMap, adOpenKeyset, adLockPessimistic, adCmdText

End Sub

Private Sub cmdExport_Click()
'####Store in Database####
Dim IntNum As Integer

'Create strImageName for testing purposes
strImageName = "c:\test\maps\Image2.bmp"
' Open the picture file
IntNum = FreeFile
Open strImageName For Binary As #IntNum
' size the byte array to appropriate size
ReDim BytImage(FileLen(strImageName))
' Read data and close file
Get #IntNum, , BytImage
Close #1

With recMap
.AddNew
'Store the BLOB
.Fields("map_name") = "test"
.Fields("map").AppendChunk BytImage
.Update

End With

End Sub


It is getting stuck when it is trying to read the data and close the file:

' Read data and close file
Get #IntNum, , BytImage


I guess I do not know enough about the FreeFile format. Am I missing something here?

Thanks for the help!

Dennis DVR
11-03-2004, 06:55 PM
read this
http://www.xtremevbtalk.com/showpost.php?p=758883&postcount=4

Original Source Code can be found here (Tutors Corner)
http://www.xtremevbtalk.com/showthread.php?t=11080

dobbs
11-04-2004, 08:27 AM
Thanks for the reply. I have seen the example from the Tutors Corner and that is where I got my example code from. The main hurtle that I am having to overcome is that I do not need the image to ever be displayed within my form. So I do not need to have it load the image within the picturebox. Do I still need to do this to make the code work correctly?

Where in the example code is 'strImageName' being set? I am guessing it is being set at this line in the code:


Open strImageName For Binary As #IntNum


If this is the case, where do I set my path for the images?

Thanks so much for the help on this!

read this
http://www.xtremevbtalk.com/showpost.php?p=758883&postcount=4

Original Source Code can be found here (Tutors Corner)
http://www.xtremevbtalk.com/showthread.php?t=11080

Dennis DVR
11-04-2004, 10:08 AM
Thanks for the reply. I have seen the example from the Tutors Corner and that is where I got my example code from. The main hurtle that I am having to overcome is that I do not need the image to ever be displayed within my form. So I do not need to have it load the image within the picturebox. Do I still need to do this to make the code work correctly?

Where in the example code is 'strImageName' being set? I am guessing it is being set at this line in the code:


Open strImageName For Binary As #IntNum


If this is the case, where do I set my path for the images?

Thanks so much for the help on this!

If you don't want to display the image in your picturebox or image control, just save the file as bmp to your hard drive. Then open the bmp file using the code in your cmdExport_click event.

dobbs
11-04-2004, 10:15 AM
Thank you for your help! I got it working the way I need it to.

If you don't want to display the image in your picturebox or image control, just save the file as bmp to your hard drive. Then open the bmp file using the code in your cmdExport_click event.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum