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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display image in a image box from database

Status
Not open for further replies.

n1a2v3i3n

Programmer
Jan 19, 2009
18
I am trying to load image in a imagebox in the click event of a combobox I have used the below code:

Private Sub cbvno_Click()
Dim Adodc3 As New ADODB.Recordset
Dim str3 As String
Dim adoconn As New ADODB.Connection
Dim rsImage As dao.Recordset
Const conChunkSize = 8192


str3 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
App.Path & "\Vechdetail.mdb;Persist Security Info=False"
Adodc3.Open " select * from details where Vehicle = '" & cbvno & "'", str3, adOpenDynamic, adLockOptimistic

txtmk.Text = Adodc3(2)
txtmdn.Text = Adodc3(3)
txtengno.Text = Adodc3(7)
txtcha.Text = Adodc3(8)


Adodc3.Close

Dim sSQL As String
Dim lKey As Long
Dim lSize As Long
Dim varChunk() As Byte
Dim lOffset As Long
Dim sPath As String
Dim nHandle As Integer
Dim iChunks As Integer
Dim nFragmentOffset As Integer
Dim i As Integer
Dim sFile As String

Set objDB = DBEngine.Workspaces(0).OpenDatabase(App.Path & "\Vechdetail.mdb")

Set rsImage = objDB.OpenRecordset("details", dbOpenDynaset)

rsImage.FindFirst "Vehicle like '" & cbvno & "'"

Screen.MousePointer = vbHourglass

If Not rsImage.EOF Then
nHandle = FreeFile
sPath = App.Path
sFile = sPath & "\output.bin"

Open sFile For Binary Access Write As nHandle

lSize = rsImage("a_image").FieldSize

iChunks = lSize \ conChunkSize
nFragmentOffset = lSize Mod conChunkSize

ReDim Buffer(nFragmentOffset) As Byte
varChunk() = rsImage("a_image").GetChunk(lOffset, nFragmentOffset)
Put nHandle, , varChunk()
lOffset = nFragmentOffset
For i = 1 To iChunks
ReDim varChunk(conChunkSize) As Byte
varChunk() = rsImage("a_image").GetChunk(lOffset, conChunkSize)
Put nHandle, , varChunk()
lOffset = lOffset + conChunkSize
txtByteCount = lOffset
DoEvents
Next
Close nHandle

Set Image1.Picture = LoadPicture(sFile, , vbLPColor)
rsImage.Close
Exit Sub
End If




End Sub

When i use this code the image is displayed in the image box but the mouse icon shows that it is porcessing something. I can use the application anyhow but the processing does not stop and i have to restart the application again.

Please can any one suggest the possible error!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top