|
-
Oct 26th, 2002, 04:09 PM
#1
Thread Starter
Lively Member
Ticky import
I have an Access database. It used to have a field name picturepath which actually store the path of the image. for example, the record would have 3 fields. Id, SSN and PicturePath and PicturePath would look like C:\Irb\image\P355923999.jpg. P355923999 is the guy's SSN. Right now I have more than 10 thousands records. It is hard to manage all these image files. So I decide to create another OLE field, which will be picture and I want to import all these image files to this field as binary file. Does someone know is there some utility which I can use? Or do I have to write a VB program to do it?
Thanks very very much.
-
Oct 27th, 2002, 01:14 PM
#2
New Member
Ok I think this will do the job.
1. Create the OLE Field in the Table
2. Open the table as Recordset in VB
3. Create a loop for each line in the recordset
Code:
'In RS loop
success = Img_FileIntoField(rs,rs.Fields("ole_name"),rs!filename)
Public Function Img_FileIntoField(rs As Recordset, fldLongBinary As Field, sFilename As String) As Boolean
On Error GoTo 100:
Dim iFN As Integer
Dim lFileLen As Long
Dim sChunk As String
With fldLongBinary
If .Type = dbLongBinary Then 'only long binary supported
' On Error GoTo StoreFileIntoFieldEH
rs.Edit 'edit the record in the recordset
.Value = "" 'clear the field
rs.Update 'update the record
rs.Edit 'now edit again
iFN = FreeFile 'get a file handle
Open sFilename For Binary As #iFN
lFileLen = LOF(iFN)
While lFileLen > 0 'loop until finished
If mclChunkSize < lFileLen Then 'chunk smaller than remaining
sChunk = String$(mclChunkSize, vbNullChar)
Else 'chunk larger than remaining
sChunk = String$(lFileLen, vbNullChar)
End If
Get #iFN, , sChunk 'get a chunk
.AppendChunk sChunk 'append to the field
lFileLen = lFileLen - mclChunkSize 'handle the next chunk
Wend
Close #iFN 'close the file
rs.Update 'store recordset onto database
Else
err.Raise vbObjectError + gclErrFieldNotLongBinary, , "Field '" & .Name & "' is not Long Binary"
End If
End With
100:
End Function
-
Oct 27th, 2002, 04:41 PM
#3
Thread Starter
Lively Member
Thanks very much. I have some code very similar like this. I was wondering if there is some utility or OCX control which can help me do this? Thanks again
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|