Option Explicit
Const FLTR = "Pictures|*.jpg*;*.gif*;*.bmp;*.ico|All Files|*.*"
Private Sub Form_Load()
Dim dbName$, tbName$
dbName = "c:\Pic1DB.mdb"
tbName = "Pictures"
'Delete statement used for testing create
'If Dir(dbName) <> "" Then Kill dbName
If Dir(dbName) = "" Then
Dim cn$
Dim cat As New ADOX.Catalog
Dim tPics As New ADOX.Table
cn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source = " & dbName & ";"
cat.Create cn
With tPics
.Name = tbName
.Columns.Append "Name", adVarWChar
.Columns!Name.Attributes = adColNullable
.Columns.Append "Picture", adLongVarBinary
End With
cat.Tables.Append tPics
Set tPics = Nothing
Set cat = Nothing
End If
With ISGData1
.Provider = "Microsoft.Jet.OLEDB.4.0"
.DataSource = dbName & ";"
.SQL = "SELECT * FROM " & tbName
.Refresh
End With
Text1.DataField = "Name"
Command1.Caption = "Add Picture"
Image1.BorderStyle = 1
End Sub
Private Sub Command1_Click()
Dim f%, L&, picFile$
On Error GoTo er1
With CommonDialog1
.CancelError = True
.Filter = FLTR
.ShowOpen
picFile = .filename
End With
f = FreeFile
Open picFile For Binary Access Read As f
L = LOF(f)
ReDim B(L) As Byte
Get f, , B()
Close f
With ISGData1.Recordset
.AddNew
!Picture.AppendChunk B()
!Name = picFile
.UpdateRecord
End With
GoTo er2
er1: Resume er2
er2: On Error GoTo 0
End Sub
Private Sub ISGData1_Reposition()
Dim L&, f%, t$
L = ISGData1.Recordset!Picture.ActualSize
ReDim B(L) As Byte
B = ISGData1.Recordset!Picture.GetChunk(L)
t = "tmp"
f = FreeFile
Open t For Binary Access Write As f
Put f, , B()
Close f
Set Image1.Picture = LoadPicture(t)
End Sub
|