|
 |
access thread: One photo for each person
Message #1 by acaxias@i... on Thu, 29 Aug 2002 13:50:00
|
|
Hi!
I have an employees database and need to have in the identification form
the individual photo of that person.
It's about 1200 people.
In books I only found the way to put a single image to "decorate" a form.
My need is diferent: to have a diferent photo for each record.
Linked?
Embeded?
What's the code, please?
My thanks for your attention.
Tony.
Message #2 by "Gregory Serrano" <SerranoG@m...> on Thu, 29 Aug 2002 17:47:57
|
|
Tony,
<< I have an employees database and need to have in the identification
form the individual photo of that person. It's about 1200 people.
In books I only found the way to put a single image to "decorate" a form.
My need is diferent: to have a diferent photo for each record. Linked?
Embeded?
What's the code, please? >>
I don't know what Books is, but no matter.
There is no code involved at all. Set up your table and create a field
name called, say, imgEmpPhoto. For data type choose OLE Object.
When you create your form, don't insert an image via the image tool;
instead use a bound object frame and bound it to imgEmpPhoto. To put a
photo in the field use something like Paint to call up your photo.
Hightlight all or part of the photo and Edit|Copy from Paint and
Edit|Paste into that object frame in Form View. Change the object
frame's .SizeMode property to Stretch or Zoom (I prefer Zoom) to fit the
photo into that size in case the picture is too big or small for the size
of the object frame. If you don't do this the photo will get cut off or
be too small to see.
Greg
Message #3 by "Carnley, Dave" <dcarnley@a...> on Thu, 29 Aug 2002 12:58:12 -0500
|
|
here is a code sample that will accept a file name and recordset (containing
an image field), read the binary image file (jpg or gif or whatever) and
stuff it into the Access field.
Public Function ReadBLOB(SourceFilePath As String, _
DestinationRecordSet As Recordset, _
DestinationFieldName As String) As Long
On Error GoTo ErrorHandler
Dim NumberOfBlocks As Integer
Dim SourceFile As Integer
Dim Index As Integer
Dim FileLength As Long
Dim LeftOverBytes As Long
Dim FileData As String
' Open the source file.
SourceFile = FreeFile()
Open SourceFilePath For Binary Access Read As SourceFile
' Get the length of the file.
FileLength = LOF(SourceFile)
If FileLength > 0 Then
' Calculate the number of blocks to read and leftover bytes.
NumberOfBlocks = FileLength \ mcBLOCK_SIZE
LeftOverBytes = FileLength Mod mcBLOCK_SIZE
DestinationRecordSet.Edit
If LeftOverBytes > 0 Then
' Read the leftover data, writing it to the table.
FileData = String$(LeftOverBytes, 32)
Get SourceFile, , FileData
DestinationRecordSet.Fields(DestinationFieldName).AppendChunk
(FileData)
End If
' Read the remaining blocks of data, writing them to the field
FileData = String$(mcBLOCK_SIZE, 32)
For Index = 1 To NumberOfBlocks
Get SourceFile, , FileData
DestinationRecordSet.Fields(DestinationFieldName).AppendChunk
(FileData)
Next Index
DestinationRecordSet.Update
ReadBLOB = FileLength
Else
ReadBLOB = 0
End If
ExitProc:
Close SourceFile
Exit Function
ErrorHandler:
Dim sErrorSource As String
sErrorSource = gcAPP_NAME & "::mdlBinaryLargeObjects::ReadBLOB"
Select Case Err.Number
Case gcODBC_ERROR, 3157
Dim errCurrent As Error
DoCmd.Beep
For Each errCurrent In Errors
DisplayError ErrorDescription:=errCurrent.Description, _
ErrorNumber:=errCurrent.Number, _
ErrorSource:=sErrorSource, _
Title:="ODBC Error"
Next errCurrent
Case Else
DoCmd.Beep
DisplayError ErrorDescription:=Err.Description, _
ErrorNumber:=Err.Number, _
ErrorSource:=sErrorSource, _
Title:="VBA Error"
End Select
ReadBLOB = 0
Resume ExitProc
End Function
-----Original Message-----
From: Gregory Serrano [mailto:SerranoG@m...]
Sent: Thursday, August 29, 2002 12:48 PM
To: Access
Subject: [access] Re: One photo for each person
Tony,
<< I have an employees database and need to have in the identification
form the individual photo of that person. It's about 1200 people.
In books I only found the way to put a single image to "decorate" a form.
My need is diferent: to have a diferent photo for each record. Linked?
Embeded?
What's the code, please? >>
I don't know what Books is, but no matter.
There is no code involved at all. Set up your table and create a field
name called, say, imgEmpPhoto. For data type choose OLE Object.
When you create your form, don't insert an image via the image tool;
instead use a bound object frame and bound it to imgEmpPhoto. To put a
photo in the field use something like Paint to call up your photo.
Hightlight all or part of the photo and Edit|Copy from Paint and
Edit|Paste into that object frame in Form View. Change the object
frame's .SizeMode property to Stretch or Zoom (I prefer Zoom) to fit the
photo into that size in case the picture is too big or small for the size
of the object frame. If you don't do this the photo will get cut off or
be too small to see.
Greg
Message #4 by "Richard Lobel" <richard@a...> on Fri, 30 Aug 2002 00:31:55 -0700
|
|
Tony,
Simply make a field in the employee table and use the OLE type for the
data type. You can't insert pictures into this field in the table, only
in a form based on the table. Then put the file path to the picture in
the form.
Richard Lobel
President
NoClassroom.com
Live Software training
Right over the Internet
richard@n...
Tel: (xxx) xxx-xxxx
Fax: (xxx) xxx-xxxx
*****ORIGINAL MESSAGE*****
I have an employees database and need to have in the identification form
the individual photo of that person.
It's about 1200 people.
In books I only found the way to put a single image to "decorate" a
form.
My need is diferent: to have a diferent photo for each record. Linked?
Embeded?
What's the code, please?
Message #5 by "Joseph O. Makong'ong'o" <jom@s...> on Fri, 30 Aug 2002 08:37:04 +0300
|
|
Hi Greg,
Your solution is cool! I am just thinking of something extra. Is there
away to read the image files stored somewhere in the filesystem instead of
copying one at atime and storing them in the DB?
Tip: Storing the full file path in the DB writing code to dynamically lookup
the photo when the form opens. Of corurse refreshing with each record
change.
Joseph
To Tony:PS. can I see your app
> -----Original Message-----
> From: Gregory Serrano [SMTP:SerranoG@m...]
> Sent: Thursday, August 29, 2002 8:48 PM
> To: Access
> Subject: [access] Re: One photo for each person
>
> Tony,
>
> << I have an employees database and need to have in the identification
> form the individual photo of that person. It's about 1200 people.
>
> In books I only found the way to put a single image to "decorate" a form.
>
> My need is diferent: to have a diferent photo for each record. Linked?
> Embeded?
>
> What's the code, please? >>
>
> I don't know what Books is, but no matter.
>
> There is no code involved at all. Set up your table and create a field
> name called, say, imgEmpPhoto. For data type choose OLE Object.
>
> When you create your form, don't insert an image via the image tool;
> instead use a bound object frame and bound it to imgEmpPhoto. To put a
> photo in the field use something like Paint to call up your photo.
> Hightlight all or part of the photo and Edit|Copy from Paint and
> Edit|Paste into that object frame in Form View. Change the object
> frame's .SizeMode property to Stretch or Zoom (I prefer Zoom) to fit the
> photo into that size in case the picture is too big or small for the size
> of the object frame. If you don't do this the photo will get cut off or
> be too small to see.
>
> Greg
Message #6 by "Gregory Serrano" <SerranoG@m...> on Fri, 30 Aug 2002 14:40:25
|
|
Tony,
<< Your solution is cool! I am just thinking of something extra. Is there
away to read the image files stored somewhere in the filesystem instead of
copying one at atime and storing them in the DB? >>
Thanks. Yes, there is. Because the staff photos I use are in someone
else's database (who may decide to kill it in the future) and I use so few
of them, I just did it that way. Richard's advice is best for that case
where there a lots of 'em.
A good way to automate it is if the user has a user ID, say last name +
first initial, then name the person's photo with the user ID. For
example, my e-mail address starts with "SerranoG". If that were my user
ID, then name my photo SerranoG.jpg or SerranoG.bmp (depending on your
format). When you specify the file, you can say that the file name is the
path + your user ID + the file extention.
Greg
Message #7 by "Carnley, Dave" <dcarnley@a...> on Fri, 30 Aug 2002 09:31:28 -0500
|
|
Not sure if I posted this already...this code will read a binary file and
stuff it into an Access image field.
Do the same thing in reverse (GetChunk) to create the file from the
database... if you want I can post that code too but wouldn't that take all
the fun out of it haha
Public Function ReadBLOB(SourceFilePath As String, _
DestinationRecordSet As Recordset, _
DestinationFieldName As String) As Long
On Error GoTo ErrorHandler
Dim NumberOfBlocks As Integer
Dim SourceFile As Integer
Dim Index As Integer
Dim FileLength As Long
Dim LeftOverBytes As Long
Dim FileData As String
' Open the source file.
SourceFile = FreeFile()
Open SourceFilePath For Binary Access Read As SourceFile
' Get the length of the file.
FileLength = LOF(SourceFile)
If FileLength > 0 Then
' Calculate the number of blocks to read and leftover bytes.
NumberOfBlocks = FileLength \ mcBLOCK_SIZE
LeftOverBytes = FileLength Mod mcBLOCK_SIZE
DestinationRecordSet.Edit
If LeftOverBytes > 0 Then
' Read the leftover data, writing it to the table.
FileData = String$(LeftOverBytes, 32)
Get SourceFile, , FileData
DestinationRecordSet.Fields(DestinationFieldName).AppendChunk
(FileData)
End If
' Read the remaining blocks of data, writing them to the field
FileData = String$(mcBLOCK_SIZE, 32)
For Index = 1 To NumberOfBlocks
Get SourceFile, , FileData
DestinationRecordSet.Fields(DestinationFieldName).AppendChunk
(FileData)
Next Index
DestinationRecordSet.Update
ReadBLOB = FileLength
Else
ReadBLOB = 0
End If
ExitProc:
Close SourceFile
Exit Function
ErrorHandler:
Dim sErrorSource As String
sErrorSource = gcAPP_NAME & "::mdlBinaryLargeObjects::ReadBLOB"
Select Case Err.Number
Case gcODBC_ERROR, 3157
Dim errCurrent As Error
DoCmd.Beep
For Each errCurrent In Errors
DisplayError ErrorDescription:=errCurrent.Description, _
ErrorNumber:=errCurrent.Number, _
ErrorSource:=sErrorSource, _
Title:="ODBC Error"
Next errCurrent
Case Else
DoCmd.Beep
DisplayError ErrorDescription:=Err.Description, _
ErrorNumber:=Err.Number, _
ErrorSource:=sErrorSource, _
Title:="VBA Error"
End Select
ReadBLOB = 0
Resume ExitProc
End Function
-----Original Message-----
From: acaxias@i... [mailto:acaxias@i...]
Sent: Thursday, August 29, 2002 8:50 AM
To: Access
Subject: [access] One photo for each person
Hi!
I have an employees database and need to have in the identification form
the individual photo of that person.
It's about 1200 people.
In books I only found the way to put a single image to "decorate" a form.
My need is diferent: to have a diferent photo for each record.
Linked?
Embeded?
What's the code, please?
My thanks for your attention.
Tony.
Message #8 by "Carnley, Dave" <dcarnley@a...> on Fri, 30 Aug 2002 11:26:41 -0500
|
|
here is some sample code... did I already post this?
Public Function ReadBLOB(SourceFilePath As String, _
DestinationRecordSet As Recordset, _
DestinationFieldName As String) As Long
On Error GoTo ErrorHandler
Dim NumberOfBlocks As Integer
Dim SourceFile As Integer
Dim Index As Integer
Dim FileLength As Long
Dim LeftOverBytes As Long
Dim FileData As String
' Open the source file.
SourceFile = FreeFile()
Open SourceFilePath For Binary Access Read As SourceFile
' Get the length of the file.
FileLength = LOF(SourceFile)
If FileLength > 0 Then
' Calculate the number of blocks to read and leftover bytes.
NumberOfBlocks = FileLength \ mcBLOCK_SIZE
LeftOverBytes = FileLength Mod mcBLOCK_SIZE
DestinationRecordSet.Edit
If LeftOverBytes > 0 Then
' Read the leftover data, writing it to the table.
FileData = String$(LeftOverBytes, 32)
Get SourceFile, , FileData
DestinationRecordSet.Fields(DestinationFieldName).AppendChunk
(FileData)
End If
' Read the remaining blocks of data, writing them to the field
FileData = String$(mcBLOCK_SIZE, 32)
For Index = 1 To NumberOfBlocks
Get SourceFile, , FileData
DestinationRecordSet.Fields(DestinationFieldName).AppendChunk
(FileData)
Next Index
DestinationRecordSet.Update
ReadBLOB = FileLength
Else
ReadBLOB = 0
End If
ExitProc:
Close SourceFile
Exit Function
ErrorHandler:
Dim sErrorSource As String
sErrorSource = gcAPP_NAME & "::mdlBinaryLargeObjects::ReadBLOB"
Select Case Err.Number
Case gcODBC_ERROR, 3157
Dim errCurrent As Error
DoCmd.Beep
For Each errCurrent In Errors
DisplayError ErrorDescription:=errCurrent.Description, _
ErrorNumber:=errCurrent.Number, _
ErrorSource:=sErrorSource, _
Title:="ODBC Error"
Next errCurrent
Case Else
DoCmd.Beep
DisplayError ErrorDescription:=Err.Description, _
ErrorNumber:=Err.Number, _
ErrorSource:=sErrorSource, _
Title:="VBA Error"
End Select
ReadBLOB = 0
Resume ExitProc
End Function
-----Original Message-----
From: Joseph O. Makong'ong'o [mailto:jom@s...]
Sent: Friday, August 30, 2002 12:37 AM
To: Access
Subject: [access] Re: One photo for each person
Hi Greg,
Your solution is cool! I am just thinking of something extra. Is there
away to read the image files stored somewhere in the filesystem instead of
copying one at atime and storing them in the DB?
Tip: Storing the full file path in the DB writing code to dynamically lookup
the photo when the form opens. Of corurse refreshing with each record
change.
Joseph
To Tony:PS. can I see your app
> -----Original Message-----
> From: Gregory Serrano [SMTP:SerranoG@m...]
> Sent: Thursday, August 29, 2002 8:48 PM
> To: Access
> Subject: [access] Re: One photo for each person
>
> Tony,
>
> << I have an employees database and need to have in the identification
> form the individual photo of that person. It's about 1200 people.
>
> In books I only found the way to put a single image to "decorate" a form.
>
> My need is diferent: to have a diferent photo for each record. Linked?
> Embeded?
>
> What's the code, please? >>
>
> I don't know what Books is, but no matter.
>
> There is no code involved at all. Set up your table and create a field
> name called, say, imgEmpPhoto. For data type choose OLE Object.
>
> When you create your form, don't insert an image via the image tool;
> instead use a bound object frame and bound it to imgEmpPhoto. To put a
> photo in the field use something like Paint to call up your photo.
> Hightlight all or part of the photo and Edit|Copy from Paint and
> Edit|Paste into that object frame in Form View. Change the object
> frame's .SizeMode property to Stretch or Zoom (I prefer Zoom) to fit the
> photo into that size in case the picture is too big or small for the size
> of the object frame. If you don't do this the photo will get cut off or
> be too small to see.
>
> Greg
Message #9 by "Carnley, Dave" <dcarnley@a...> on Fri, 30 Aug 2002 12:43:58 -0500
|
|
sorry for multiple posts... either my or p2p email server is getting
goofy...
-----Original Message-----
From: Carnley, Dave [mailto:dcarnley@a...]
Sent: Friday, August 30, 2002 9:31 AM
To: Access
Subject: [access] One photo for each person
Not sure if I posted this already...this code will read a binary file and
stuff it into an Access image field.
Do the same thing in reverse (GetChunk) to create the file from the
database... if you want I can post that code too but wouldn't that take all
the fun out of it haha
Public Function ReadBLOB(SourceFilePath As String, _
DestinationRecordSet As Recordset, _
DestinationFieldName As String) As Long
On Error GoTo ErrorHandler
Dim NumberOfBlocks As Integer
Dim SourceFile As Integer
Dim Index As Integer
Dim FileLength As Long
Dim LeftOverBytes As Long
Dim FileData As String
' Open the source file.
SourceFile = FreeFile()
Open SourceFilePath For Binary Access Read As SourceFile
' Get the length of the file.
FileLength = LOF(SourceFile)
If FileLength > 0 Then
' Calculate the number of blocks to read and leftover bytes.
NumberOfBlocks = FileLength \ mcBLOCK_SIZE
LeftOverBytes = FileLength Mod mcBLOCK_SIZE
DestinationRecordSet.Edit
If LeftOverBytes > 0 Then
' Read the leftover data, writing it to the table.
FileData = String$(LeftOverBytes, 32)
Get SourceFile, , FileData
DestinationRecordSet.Fields(DestinationFieldName).AppendChunk
(FileData)
End If
' Read the remaining blocks of data, writing them to the field
FileData = String$(mcBLOCK_SIZE, 32)
For Index = 1 To NumberOfBlocks
Get SourceFile, , FileData
DestinationRecordSet.Fields(DestinationFieldName).AppendChunk
(FileData)
Next Index
DestinationRecordSet.Update
ReadBLOB = FileLength
Else
ReadBLOB = 0
End If
ExitProc:
Close SourceFile
Exit Function
ErrorHandler:
Dim sErrorSource As String
sErrorSource = gcAPP_NAME & "::mdlBinaryLargeObjects::ReadBLOB"
Select Case Err.Number
Case gcODBC_ERROR, 3157
Dim errCurrent As Error
DoCmd.Beep
For Each errCurrent In Errors
DisplayError ErrorDescription:=errCurrent.Description, _
ErrorNumber:=errCurrent.Number, _
ErrorSource:=sErrorSource, _
Title:="ODBC Error"
Next errCurrent
Case Else
DoCmd.Beep
DisplayError ErrorDescription:=Err.Description, _
ErrorNumber:=Err.Number, _
ErrorSource:=sErrorSource, _
Title:="VBA Error"
End Select
ReadBLOB = 0
Resume ExitProc
End Function
-----Original Message-----
From: acaxias@i... [mailto:acaxias@i...]
Sent: Thursday, August 29, 2002 8:50 AM
To: Access
Subject: [access] One photo for each person
Hi!
I have an employees database and need to have in the identification form
the individual photo of that person.
It's about 1200 people.
In books I only found the way to put a single image to "decorate" a form.
My need is diferent: to have a diferent photo for each record.
Linked?
Embeded?
What's the code, please?
My thanks for your attention.
Tony.
|
|
 |