Public Function GetImage(Optional Filename As String) As Variant On Error GoTo ProcErr Dim objRS As adodb.Recordset Dim strSQL As String Dim Chunk() As Byte
Set objRS = New adodb.Recordset
'strSQL = "select thumb from tblpictures where idpict='" & tblID(ThumbIndex) & "'" strSQL = "select thumb from tblpictures where idpict= " & thumb 'strSQL = "select thumb from tblpictures where idpict='387'" 'db.Execute strSQL objRS.Open strSQL, db, adOpenForwardOnly, adLockReadOnly
If objRS.BOF And objRS.EOF Then GetImage = 0 GoTo ProcExit ElseIf IsNull(objRS.Fields(0)) Then 'ErrNumber = 1001 'ErrDesc = "字段为空" GoTo ProcExit End If
Chunk() = objRS.Fields(0).GetChunk(objRS.Fields(0).ActualSize) Set GetImage = Chunk2Image(Chunk(), Filename)ProcExit: On Error Resume Next 'objRS.Close ' Chunk() = objRS.Fields(0).GetChunk(0) Set GetImage = Chunk2Image(Chunk(), Filename) ' Set objRS = Nothing Exit FunctionProcErr: GetImage = 0 Resume ProcExit End Function Private Function Chunk2Image(Chunk() As Byte, Optional Filename As String) As Variant On Error GoTo ProcErr Dim KeepFile As Boolean Dim Datafile As Integer KeepFile = True If Trim(Filename) = "" Then Filename = "c:\tmpxxdb.fil" KeepFile = False End If Datafile = FreeFile Open Filename For Binary Access Write As Datafile Put Datafile, , Chunk() Close DatafileProcExit: Set Chunk2Image = LoadPicture(Filename) On Error Resume Next ' If Not KeepFile Then Kill filename Exit FunctionProcErr: On Error Resume Next Kill Filename Chunk2Image = 0 End Function
On Error GoTo ProcErr Dim objRS As adodb.Recordset
Dim strSQL As String
Dim Chunk() As Byte
Set objRS = New adodb.Recordset
'strSQL = "select thumb from tblpictures where idpict='" & tblID(ThumbIndex) & "'"
strSQL = "select thumb from tblpictures where idpict= " & thumb
'strSQL = "select thumb from tblpictures where idpict='387'"
'db.Execute strSQL
objRS.Open strSQL, db, adOpenForwardOnly, adLockReadOnly
If objRS.BOF And objRS.EOF Then
GetImage = 0
GoTo ProcExit
ElseIf IsNull(objRS.Fields(0)) Then
'ErrNumber = 1001
'ErrDesc = "字段为空"
GoTo ProcExit
End If
Chunk() = objRS.Fields(0).GetChunk(objRS.Fields(0).ActualSize)
Set GetImage = Chunk2Image(Chunk(), Filename)ProcExit:
On Error Resume Next
'objRS.Close
' Chunk() = objRS.Fields(0).GetChunk(0)
Set GetImage = Chunk2Image(Chunk(), Filename)
' Set objRS = Nothing Exit FunctionProcErr:
GetImage = 0
Resume ProcExit
End Function
Private Function Chunk2Image(Chunk() As Byte, Optional Filename As String) As Variant
On Error GoTo ProcErr
Dim KeepFile As Boolean
Dim Datafile As Integer KeepFile = True
If Trim(Filename) = "" Then
Filename = "c:\tmpxxdb.fil"
KeepFile = False
End If Datafile = FreeFile
Open Filename For Binary Access Write As Datafile
Put Datafile, , Chunk()
Close DatafileProcExit:
Set Chunk2Image = LoadPicture(Filename)
On Error Resume Next
' If Not KeepFile Then Kill filename
Exit FunctionProcErr:
On Error Resume Next
Kill Filename
Chunk2Image = 0
End Function