Answer for:

Uploading jpeg picture to ms access via Visual basic 6

Message 9 of 9

View entire thread
0 Votes

Dim FileLength As Long
Dim Numblocks As Integer
Dim LeftOver As Long
Const BlockSize = 1000000 'This size can be experimented with for
Dim ByteData() As Byte 'Byte array for picture file.
Dim DestFileNum As Integer
Dim DiskFile As String
Dim rr As Integer

''''''''''''''''''Insert Picture in Table'''''''''''''''''''
If Trim(CommonDialog1.FileName) = "" Then
CommonDialog1.FileName = "App.path & "\photo.jpg"
End If

Open CommonDialog1.FileName For Binary As #1
ReDim MyArray(LOF(1))
Get #1, , MyArray()
Close #1
''''''''''''insert picture in table''''''''

RSDetails.Fields("emp_photo").AppendChunk MyArray()
''Rsdetails is the recordset of table'''
'''"emp_photo" is field's of table'''
''Appendchunk is use for load image in table''

''''''''''''''Display Picture In Image OR PictureBox From Table'''''''''''
DiskFile = "App.path & "\photo.jpg"

If Len(Dir$(DiskFile)) > 0 Then
Kill DiskFile
End If

DestFileNum = FreeFile
Open DiskFile For Binary As DestFileNum
FileLength = TempDetails("emp_photo").ActualSize
Numblocks = FileLength / BlockSize
LeftOver = FileLength Mod BlockSize

ByteData() = TempDetails("emp_photo").GetChunk(LeftOver)
Put DestFileNum, , ByteData()

For I = 1 To Numblocks
ByteData() = TempDetails("emp_photo").GetChunk(BlockSize)
Put DestFileNum, , ByteData()
Next I

Close DestFileNum
Image1.Picture = LoadPicture("App.path & "\photo.jpg")
'''''''''''''''end modifiction section'''''''''''''''