By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,602 Members | 997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,602 IT Pros & Developers. It's quick & easy.

Add photo to form/report

fnwtech
P: 48
I have been reading the forums, but I really need a step by step. I took a one day vb class about 3 years ago, so I know just enough to be confused!

I have a database of students that I have to add photos to. In Access 2000, I had added them using the OLE field type. I can't seem to get Access 2003 to do this, even after installing Photo Editor. In my reading, it appears that using a text type and using a path or using BLOBs are better solutions. I can't seem to figure out either.

I would appreciate someone walking me through the steps.

I have a table for the images (though I have not imported them yet) named tblStudentPhoto with two fields, studentstateID and Photo. I had the photo field as an OLE but changed it to text. Should I type the path into this field? If so, do I start with the drive letter?
May 28 '08 #1
Share this Question
Share on Google+
27 Replies

nico5038
Expert 2.5K+
P: 3,072
Check out these storing BLOB in Access links:
http://www26.brinkster.com/alzowze/home.asp
http://www.jamiessoftware.tk/article...ingimages.html

The first one even holds some fine access sample databases.

To insert an image in A2003 you'll need an OLE field and use the Insert/Object popup menu to store it. It does however take a lot of additional space and I would go for the "BLOB" solution.

Nic;o)
May 29 '08 #2

ADezii
Expert 5K+
P: 8,750
I have been reading the forums, but I really need a step by step. I took a one day vb class about 3 years ago, so I know just enough to be confused!

I have a database of students that I have to add photos to. In Access 2000, I had added them using the OLE field type. I can't seem to get Access 2003 to do this, even after installing Photo Editor. In my reading, it appears that using a text type and using a path or using BLOBs are better solutions. I can't seem to figure out either.

I would appreciate someone walking me through the steps.

I have a table for the images (though I have not imported them yet) named tblStudentPhoto with two fields, studentstateID and Photo. I had the photo field as an OLE but changed it to text. Should I type the path into this field? If so, do I start with the drive letter?
Although not the most efficient Method, the simplest especially for a Newbie with limited VBA skills, would be to dynamically load the actual Photo Image into an Image Control on a Form at run time. This would require no storage of OLE Objects, and virtually no overhead. The only requirement would be to store the name of the Photo in a Text Field such as: BartSimpson.jpg, 209768871.jpg, etc. The code will take care of the rest and the Photos would remain external to the DB.
May 30 '08 #3

fnwtech
P: 48
Although not the most efficient Method, the simplest especially for a Newbie with limited VBA skills, would be to dynamically load the actual Photo Image into an Image Control on a Form at run time. This would require no storage of OLE Objects, and virtually no overhead. The only requirement would be to store the name of the Photo in a Text Field such as: BartSimpson.jpg, 209768871.jpg, etc. The code will take care of the rest and the Photos would remain external to the DB.

What would be the code to add the photo to the image control?
Jun 2 '08 #4

ADezii
Expert 5K+
P: 8,750
What would be the code to add the photo to the image control?
The code would be added to the Current() Event of the Form and would be similar to:
Expand|Select|Wrap|Line Numbers
  1. 'gPHOTO_PATH would be a Global Constant similar to:
  2. 'Public Const gPHOTO_PATH As String = "\Photos\"
  3. 'Photo Images would be stored in a Photos Directory under the
  4. 'Current Project Path
  5.  
  6. 'Can be set in the Properties Window of the Image Control
  7. Me![imgPhoto].SizeMode = acOLESizeStretch
  8.  
  9. If IsNull(Me![txtPhotoFile]) Then       'No Picture File, display no Picture
  10.   Me![imgPhoto].Picture = ""
  11. Else
  12.   'Picture File listed, but does the Path and actual File exist?
  13.   If Dir(CurrentProject.Path & gPHOTO_PATH & Me!txtPhotoFile, vbNormal) <> "" Then    ' it exists
  14.     Me![imgFieldInventory].Picture = CurrentProject.Path & gPHOTO_PATH & Me!txtPhotoFile
  15.   Else
  16.     'display some Error Message to the User
  17.   End If
  18. End If
Jun 3 '08 #5

100+
P: 222
I have been reading the forums, but I really need a step by step. I took a one day vb class about 3 years ago, so I know just enough to be confused!

I have a database of students that I have to add photos to. In Access 2000, I had added them using the OLE field type. I can't seem to get Access 2003 to do this, even after installing Photo Editor. In my reading, it appears that using a text type and using a path or using BLOBs are better solutions. I can't seem to figure out either.

I would appreciate someone walking me through the steps.

I have a table for the images (though I have not imported them yet) named tblStudentPhoto with two fields, studentstateID and Photo. I had the photo field as an OLE but changed it to text. Should I type the path into this field? If so, do I start with the drive letter?

Hi

I think I am able to help you on this IDEA.

I designed a database that can navigate thought 11000 picture on access 2003 and it is working well.


The Idea is to save all pictures in a specific Folder. In my side I used the same root of my database in a folder named "Image". In your table tblStudentPhoto each studentstateID must have in Photo the name of his image.(JUST THE NAME AND DON'T FORGET THE FILE TYPE EXAMPLE image1.JPG) after that you have to insert an image place.
every time you want to navigate and see the picture that it is related to the studentstateID you have to write a small code.

your_image_place.image.picture=the root of you database + Photo

I can provide you many codes (OF COURSE THANKS FOR EXPERT PEOPLE IN THE SCRIPTS)to find the root of your database also to auto copy the image after choose it into the specific folder ...


WASSIM S DACCACHE
Jun 3 '08 #6

fnwtech
P: 48
The code would be added to the Current() Event of the Form and would be similar to:
Expand|Select|Wrap|Line Numbers
  1. 'gPHOTO_PATH would be a Global Constant similar to:
  2. 'Public Const gPHOTO_PATH As String = "\Photos\"
  3. 'Photo Images would be stored in a Photos Directory under the
  4. 'Current Project Path
  5.  
  6. 'Can be set in the Properties Window of the Image Control
  7. Me![imgPhoto].SizeMode = acOLESizeStretch
  8.  
  9. If IsNull(Me![txtPhotoFile]) Then       'No Picture File, display no Picture
  10.   Me![imgPhoto].Picture = ""
  11. Else
  12.   'Picture File listed, but does the Path and actual File exist?
  13.   If Dir(CurrentProject.Path & gPHOTO_PATH & Me!txtPhotoFile, vbNormal) <> "" Then    ' it exists
  14.     Me![imgFieldInventory].Picture = CurrentProject.Path & gPHOTO_PATH & Me!txtPhotoFile
  15.   Else
  16.     'display some Error Message to the User
  17.   End If
  18. End If

So, I have tblStudentPhoto with two fields, studentstateID and Photo. I need to make Photo a text field with just the full file name of the photo. If I put the photos in a directory in the same directory as the database and name it photos, what part of the code would need to be changed to point to the photos?
Jun 3 '08 #7

100+
P: 222
So, I have tblStudentPhoto with two fields, studentstateID and Photo. I need to make Photo a text field with just the full file name of the photo. If I put the photos in a directory in the same directory as the database and name it photos, what part of the code would need to be changed to point to the photos?
Put this code on a module
Expand|Select|Wrap|Line Numbers
  1.          Function GetPath()
  2.    'Returns the path to currently opened MDB or ADP
  3.    GetPath = CurrentProject.Path
  4. End Function
  5.  
then on your form on current action use VBA and write this code


Me.Image.Picture = GetPath() + "/photos/" + [tblStudentPhoto ]

Don't forget to add a picture on your form with a name "image"

wassim s daccache
CCE
Jun 3 '08 #8

ADezii
Expert 5K+
P: 8,750
So, I have tblStudentPhoto with two fields, studentstateID and Photo. I need to make Photo a text field with just the full file name of the photo. If I put the photos in a directory in the same directory as the database and name it photos, what part of the code would need to be changed to point to the photos?
  1. In a Standard Code Module, place this Constant Declaration:
    Expand|Select|Wrap|Line Numbers
    1. Public Const gPHOTO_PATH As String = "\Photos\"
  2. In the Current() Event of your Form, place this code:
    Expand|Select|Wrap|Line Numbers
    1. 'Photo Images would be stored in a Photos Directory under the
    2. 'Current Project Path
    3.  
    4. 'Can be set in the Properties Window of the Image Control
    5. Me![imgPhoto].SizeMode = acOLESizeStretch
    6.  
    7. 'Name your Image Control imgPhoto
    8. If IsNull(Me![Photo]) Then       'No Picture File, display no Picture
    9.   Me![imgPhoto].Picture = ""
    10. Else
    11.   'Picture File listed, but does the Path and actual File exist?
    12.   If Dir(CurrentProject.Path & gPHOTO_PATH & Me![Photo], vbNormal) <> "" Then    ' it exists
    13.     Me![imgPhoto].Picture = CurrentProject.Path & gPHOTO_PATH & Me![Photo]
    14.   Else
    15.     'display some Error Message to the User
    16.   End If
    17. End If
  3. If you are still having trouble, I can make a Test Database available to your as an Attachment to better see what is going on. Just let me know.
Jun 3 '08 #9

fnwtech
P: 48
  1. In a Standard Code Module, place this Constant Declaration:
    Expand|Select|Wrap|Line Numbers
    1. Public Const gPHOTO_PATH As String = "\Photos\"
  2. In the Current() Event of your Form, place this code:
    Expand|Select|Wrap|Line Numbers
    1. 'Photo Images would be stored in a Photos Directory under the
    2. 'Current Project Path
    3.  
    4. 'Can be set in the Properties Window of the Image Control
    5. Me![imgPhoto].SizeMode = acOLESizeStretch
    6.  
    7. 'Name your Image Control imgPhoto
    8. If IsNull(Me![Photo]) Then       'No Picture File, display no Picture
    9.   Me![imgPhoto].Picture = ""
    10. Else
    11.   'Picture File listed, but does the Path and actual File exist?
    12.   If Dir(CurrentProject.Path & gPHOTO_PATH & Me![Photo], vbNormal) <> "" Then    ' it exists
    13.     Me![imgPhoto].Picture = CurrentProject.Path & gPHOTO_PATH & Me![Photo]
    14.   Else
    15.     'display some Error Message to the User
    16.   End If
    17. End If
  3. If you are still having trouble, I can make a Test Database available to your as an Attachment to better see what is going on. Just let me know.
OK, I get where to put #2 and think I am set on that. But for step one, you say In a Standard Code Module, place this Constant Declaration: Do I do this using the Module object? Thanks so much for your help!
Jun 3 '08 #10

ADezii
Expert 5K+
P: 8,750
OK, I get where to put #2 and think I am set on that. But for step one, you say In a Standard Code Module, place this Constant Declaration: Do I do this using the Module object? Thanks so much for your help!
Yes, create a New Module if you do not have an existing one, then add this Declaration.
Jun 3 '08 #11

fnwtech
P: 48
Yes, create a New Module if you do not have an existing one, then add this Declaration.

Okay, now when I launch the form, I receive an error
Assessment Database can't find the field 'imgPhoto' referred to in your expression.

Is this because my field is named Photo not imgPhoto?
Jun 3 '08 #12

ADezii
Expert 5K+
P: 8,750
Okay, now when I launch the form, I receive an error
Assessment Database can't find the field 'imgPhoto' referred to in your expression.

Is this because my field is named Photo not imgPhoto?
The Name of the Image Control, not a Field, is named imgPhoto (that's why the img Prefix). The Field Name containing the Photo File Name is [Photo] as requested by you.
Jun 3 '08 #13

fnwtech
P: 48
The Name of the Image Control, not a Field, is named imgPhoto (that's why the img Prefix). The Field Name containing the Photo File Name is [Photo] as requested by you.

Okay, got that fixed, I just changed the image control to imgPhoto. Now when I launch, it stops at this line:
Me![photo].SizeMode = acOLESizeStretch

The error is:
Run-time Error 438
Object doesn't support this property or method.

The object is a bound object frame.
Jun 3 '08 #14

ADezii
Expert 5K+
P: 8,750
Okay, got that fixed, I just changed the image control to imgPhoto. Now when I launch, it stops at this line:
Me![photo].SizeMode = acOLESizeStretch

The error is:
Run-time Error 438
Object doesn't support this property or method.

The object is a bound object frame.
It should be:
Expand|Select|Wrap|Line Numbers
  1. Me![imgPhoto].SizeMode = acOLESizeStretch
Jun 3 '08 #15

fnwtech
P: 48
It should be:
Expand|Select|Wrap|Line Numbers
  1. Me![imgPhoto].SizeMode = acOLESizeStretch

Okay, now it stops on this line:
Me![imgPhoto].Picture = CurrentProject.Path & gPHOTO_PATH & Me![photo]
Jun 3 '08 #16

ADezii
Expert 5K+
P: 8,750
Okay, now it stops on this line:
Me![imgPhoto].Picture = CurrentProject.Path & gPHOTO_PATH & Me![photo]
Would you be willing to send me the Database as an E-Mail Attachment?
Jun 3 '08 #17

fnwtech
P: 48
Would you be willing to send me the Database as an E-Mail Attachment?
It is quite a large database, but I can see if I can thin it down by removing some of the data. If you don't mind... that would be great.
Jun 4 '08 #18

ADezii
Expert 5K+
P: 8,750
It is quite a large database, but I can see if I can thin it down by removing some of the data. If you don't mind... that would be great.
I'll send you my E-Mail Address in a Private Message. I'll only need approximately 12 Records with the corresponding Photo Files (*.bmp, *.jpg., etc.). Make sure the actual File Names are the same as those stored in the Database.
Jun 4 '08 #19

ADezii
Expert 5K+
P: 8,750
Because of the nature of the photographic files, I E-Mailed a corrected version of the Database to your E-Mail Address. I'm sure that you understand. Kindly post all other relevant information here at Bytes. Thanks.
Jun 4 '08 #20

fnwtech
P: 48
Because of the nature of the photographic files, I E-Mailed a corrected version of the Database to your E-Mail Address. I'm sure that you understand. Kindly post all other relevant information here at Bytes. Thanks.

Okay, this places the picture file name on the form. Is there a way to have it place the actual photo on the form?
Jun 4 '08 #21

fnwtech
P: 48
Okay, this places the picture file name on the form. Is there a way to have it place the actual photo on the form?

Oops, my mistake. Once I moved the database into the correct folder, it worked.
Jun 4 '08 #22

fnwtech
P: 48
Oops, my mistake. Once I moved the database into the correct folder, it worked.

Okay, I finally have it working. I don't know how my photo field ended up a memo field! Thanks! Now I just need to add this so that the report will also pull the photo in!

Thank you so much. I was really under the gun here!
Jun 4 '08 #23

ADezii
Expert 5K+
P: 8,750
Okay, I finally have it working. I don't know how my photo field ended up a memo field! Thanks! Now I just need to add this so that the report will also pull the photo in!

Thank you so much. I was really under the gun here!
Not a problem, glad it all worked out for you.
Jun 4 '08 #24

fnwtech
P: 48
Thanks for the help on the form, ADezzi,

Now I am trying to get this to work on the report. This is the more critical piece form me, as these need to be printed next week.

Using the code from the form (and I may be way off here):

'Photo Images would be stored in a Photos Directory under the
'Current Project Path

'Not necessary , since I set the Size Mode Property of the Image Control to Stretch
'Me![imgPhoto].SizeMode = acOLESizeStretch

If IsNull(Me![photo]) Then 'No Picture File, display no Picture
Me![imgPhoto].Picture = ""
Else
'Picture File listed, but does the Path and actual File exist?
If Dir(CurrentProject.Path & gPHOTO_PATH & Me![photo], vbNormal) <> ""
Then
'it exists
Me![imgPhoto].Picture = CurrentProject.Path & gPHOTO_PATH & Me![photo]
Else
'display some Error Message to the User, get rid of existing Picture
Me![imgPhoto].Picture = ""
End If
End If

The bolded line is where it is stopping. first, I put this in under the Open Event - not sure if that is where it should be. I did fix the query this report uses, and that is working fine. Any guidance on what is causing this would be greatly appreciated!
Again, thanks
Jun 5 '08 #25

ADezii
Expert 5K+
P: 8,750
Thanks for the help on the form, ADezzi,

Now I am trying to get this to work on the report. This is the more critical piece form me, as these need to be printed next week.

Using the code from the form (and I may be way off here):

'Photo Images would be stored in a Photos Directory under the
'Current Project Path

'Not necessary , since I set the Size Mode Property of the Image Control to Stretch
'Me![imgPhoto].SizeMode = acOLESizeStretch

If IsNull(Me![photo]) Then 'No Picture File, display no Picture
Me![imgPhoto].Picture = ""
Else
'Picture File listed, but does the Path and actual File exist?
If Dir(CurrentProject.Path & gPHOTO_PATH & Me![photo], vbNormal) <> ""
Then
'it exists
Me![imgPhoto].Picture = CurrentProject.Path & gPHOTO_PATH & Me![photo]
Else
'display some Error Message to the User, get rid of existing Picture
Me![imgPhoto].Picture = ""
End If
End If

The bolded line is where it is stopping. first, I put this in under the Open Event - not sure if that is where it should be. I did fix the query this report uses, and that is working fine. Any guidance on what is causing this would be greatly appreciated!
Again, thanks
Assuming everything else is the same, place the provided code into the Format() Event of the Detail Section of the Report.
Jun 5 '08 #26

fnwtech
P: 48
Assuming everything else is the same, place the provided code into the Format() Event of the Detail Section of the Report.
That was it! Perfect.
Thank you so much!
Jun 5 '08 #27

ADezii
Expert 5K+
P: 8,750
That was it! Perfect.
Thank you so much!
You are quite welcome, fnwtech.
Jun 5 '08 #28

Post your reply

Sign in to post your reply or Sign up for a free account.