Programatically insert pictures into a table field

P

PaulB50

G'day I am having trouble setting up access basic routine to look for a jpg
file, and save it to a table field. I am handling the table record as a class
object & all is fine with all other data types except picture files.

Table is tblCheque with a heap of fields
ChequeID as autonumber
Name as string
RecDate as date
ChequeImage as oleobject

The class object i(claStuff) s defined with Get & Let properties as well as
load (from table) & Save methods. these again work for all other datatypes.

So I get a recordset that need picture updates required - that works; & step
through them sequentially to the eof, tested that without the picture code &
the code works.

Sub StoreImages(MyBankAccountID As Long)
'The object of this routine is to accept the bank account id, the cheque
numbers
'& the image MyImagePath of the jpg files that comprise the evidence set
for these transactions

Dim MyDb As DAO.Database
Dim rstCheques As DAO.Recordset
Dim MyCheque As New claCheque
Dim strRecordset As String
Dim CheqID As Long
Dim Cheqnum As Long
Dim ImagePath As String
Dim RecCount As Long

Set MyDb = CurrentDb
strRecordset = "SELECT tblCheque.ChequeID, tblCheque.CaseID,
tblCheque.BankAccountID, tblCheque.ChequeNum" _
& " FROM tblCheque" _
& " WHERE (tblCheque.CaseID = 1) And
(tblCheque.BankAccountID = " & MyBankAccountID & ")" _
& " ORDER BY tblCheque.ChequeID"
Set rstCheques = MyDb.OpenRecordset(strRecordset, dbOpenDynaset)

With rstCheques
RecCount = .RecordCount
Do Until CheqID > 5 '.EOF
CheqID = ![ChequeID]
Cheqnum = ![ChequeNum]

With MyCheque
MyCheque.ChequeID = CheqID
If MyCheque.Load Then
ImagePath = GetTif(Cheqnum, "Butt")
MyCheque.ButtImage = LoadPicture(ImagePath)

ImagePath = GetTif(Cheqnum, "Face")
MyCheque.ChequeImage = LoadPicture(ImagePath)

ImagePath = GetTif(Cheqnum, "Back")
MyCheque.ReverseImage = LoadPicture(ImagePath)
Else
Exit Do
End If
MyCheque.Save
End With 'MyCheque
.MoveNext
RecCount = RecCount - 1
Loop

End With 'rstCheques


rstCheques.Close

End Sub

How do I declare and set the variables to achieve this, I expect that they
will need to be set in the class object

regards
 
D

dymondjack

Paul,

I've never done this with a class, but I've done something similar with
pictures. My method involves storing the Filepath in the table (assuming you
have a central location for your cheque images).

If you have a picture control on a form or report, you can programmatically
set its source to the filepath in your table. That turns it from working
with OLE objects to plain old string variables. (I set the picture control to
Linked rather than Embedded).

I don't know if something like this is what you are looking for, but I
thought I'd throw it out there. Unfortunately I have no experience with OLE
and very little with classes, but I've made a small pictures database like
this and it seems to work well (e.i. images load quickly from the local
computer)

hth

--
Jack Leach
www.tristatemachine.com

- "First, get your information. Then, you can distort it at your leisure."
- Mark Twain


PaulB50 said:
G'day I am having trouble setting up access basic routine to look for a jpg
file, and save it to a table field. I am handling the table record as a class
object & all is fine with all other data types except picture files.

Table is tblCheque with a heap of fields
ChequeID as autonumber
Name as string
RecDate as date
ChequeImage as oleobject

The class object i(claStuff) s defined with Get & Let properties as well as
load (from table) & Save methods. these again work for all other datatypes.

So I get a recordset that need picture updates required - that works; & step
through them sequentially to the eof, tested that without the picture code &
the code works.

Sub StoreImages(MyBankAccountID As Long)
'The object of this routine is to accept the bank account id, the cheque
numbers
'& the image MyImagePath of the jpg files that comprise the evidence set
for these transactions

Dim MyDb As DAO.Database
Dim rstCheques As DAO.Recordset
Dim MyCheque As New claCheque
Dim strRecordset As String
Dim CheqID As Long
Dim Cheqnum As Long
Dim ImagePath As String
Dim RecCount As Long

Set MyDb = CurrentDb
strRecordset = "SELECT tblCheque.ChequeID, tblCheque.CaseID,
tblCheque.BankAccountID, tblCheque.ChequeNum" _
& " FROM tblCheque" _
& " WHERE (tblCheque.CaseID = 1) And
(tblCheque.BankAccountID = " & MyBankAccountID & ")" _
& " ORDER BY tblCheque.ChequeID"
Set rstCheques = MyDb.OpenRecordset(strRecordset, dbOpenDynaset)

With rstCheques
RecCount = .RecordCount
Do Until CheqID > 5 '.EOF
CheqID = ![ChequeID]
Cheqnum = ![ChequeNum]

With MyCheque
MyCheque.ChequeID = CheqID
If MyCheque.Load Then
ImagePath = GetTif(Cheqnum, "Butt")
MyCheque.ButtImage = LoadPicture(ImagePath)

ImagePath = GetTif(Cheqnum, "Face")
MyCheque.ChequeImage = LoadPicture(ImagePath)

ImagePath = GetTif(Cheqnum, "Back")
MyCheque.ReverseImage = LoadPicture(ImagePath)
Else
Exit Do
End If
MyCheque.Save
End With 'MyCheque
.MoveNext
RecCount = RecCount - 1
Loop

End With 'rstCheques


rstCheques.Close

End Sub

How do I declare and set the variables to achieve this, I expect that they
will need to be set in the class object

regards
 
P

PaulB50

Thanks ol' mate, I tried that last night & it works. What I was trying to
achieve was a high level of evidence integrity, whereby once an image is
stored it can be viewed, printed etc but not changed in any way. My devious
mind could find ways to corrupt the evidence if I had the motive, so the
security of that evidence is paramount.

If anyone want to see how interact between all objects and database tables,
eg through class objects, I will be happy to post a short example - please
advise

thanks & regards PaulB

dymondjack said:
Paul,

I've never done this with a class, but I've done something similar with
pictures. My method involves storing the Filepath in the table (assuming you
have a central location for your cheque images).

If you have a picture control on a form or report, you can programmatically
set its source to the filepath in your table. That turns it from working
with OLE objects to plain old string variables. (I set the picture control to
Linked rather than Embedded).

I don't know if something like this is what you are looking for, but I
thought I'd throw it out there. Unfortunately I have no experience with OLE
and very little with classes, but I've made a small pictures database like
this and it seems to work well (e.i. images load quickly from the local
computer)

hth

--
Jack Leach
www.tristatemachine.com

- "First, get your information. Then, you can distort it at your leisure."
- Mark Twain


PaulB50 said:
G'day I am having trouble setting up access basic routine to look for a jpg
file, and save it to a table field. I am handling the table record as a class
object & all is fine with all other data types except picture files.

Table is tblCheque with a heap of fields
ChequeID as autonumber
Name as string
RecDate as date
ChequeImage as oleobject

The class object i(claStuff) s defined with Get & Let properties as well as
load (from table) & Save methods. these again work for all other datatypes.

So I get a recordset that need picture updates required - that works; & step
through them sequentially to the eof, tested that without the picture code &
the code works.

Sub StoreImages(MyBankAccountID As Long)
'The object of this routine is to accept the bank account id, the cheque
numbers
'& the image MyImagePath of the jpg files that comprise the evidence set
for these transactions

Dim MyDb As DAO.Database
Dim rstCheques As DAO.Recordset
Dim MyCheque As New claCheque
Dim strRecordset As String
Dim CheqID As Long
Dim Cheqnum As Long
Dim ImagePath As String
Dim RecCount As Long

Set MyDb = CurrentDb
strRecordset = "SELECT tblCheque.ChequeID, tblCheque.CaseID,
tblCheque.BankAccountID, tblCheque.ChequeNum" _
& " FROM tblCheque" _
& " WHERE (tblCheque.CaseID = 1) And
(tblCheque.BankAccountID = " & MyBankAccountID & ")" _
& " ORDER BY tblCheque.ChequeID"
Set rstCheques = MyDb.OpenRecordset(strRecordset, dbOpenDynaset)

With rstCheques
RecCount = .RecordCount
Do Until CheqID > 5 '.EOF
CheqID = ![ChequeID]
Cheqnum = ![ChequeNum]

With MyCheque
MyCheque.ChequeID = CheqID
If MyCheque.Load Then
ImagePath = GetTif(Cheqnum, "Butt")
MyCheque.ButtImage = LoadPicture(ImagePath)

ImagePath = GetTif(Cheqnum, "Face")
MyCheque.ChequeImage = LoadPicture(ImagePath)

ImagePath = GetTif(Cheqnum, "Back")
MyCheque.ReverseImage = LoadPicture(ImagePath)
Else
Exit Do
End If
MyCheque.Save
End With 'MyCheque
.MoveNext
RecCount = RecCount - 1
Loop

End With 'rstCheques


rstCheques.Close

End Sub

How do I declare and set the variables to achieve this, I expect that they
will need to be set in the class object

regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top