Add photo to form/report

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fnwtech
    New Member
    • Oct 2007
    • 48

    Add photo to form/report

    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?
  • nico5038
    Recognized Expert Specialist
    • Nov 2006
    • 3080

    #2
    Check out these storing BLOB in Access links:



    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)

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Originally posted by fnwtech
      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.

      Comment

      • fnwtech
        New Member
        • Oct 2007
        • 48

        #4
        Originally posted by ADezii
        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?

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          Originally posted by fnwtech
          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:
          [CODE=vb]
          'gPHOTO_PATH would be a Global Constant similar to:
          'Public Const gPHOTO_PATH As String = "\Photos\"
          'Photo Images would be stored in a Photos Directory under the
          'Current Project Path

          'Can be set in the Properties Window of the Image Control
          Me![imgPhoto].SizeMode = acOLESizeStretc h

          If IsNull(Me![txtPhotoFile]) Then 'No Picture File, display no Picture
          Me![imgPhoto].Picture = ""
          Else
          'Picture File listed, but does the Path and actual File exist?
          If Dir(CurrentProj ect.Path & gPHOTO_PATH & Me!txtPhotoFile , vbNormal) <> "" Then ' it exists
          Me![imgFieldInvento ry].Picture = CurrentProject. Path & gPHOTO_PATH & Me!txtPhotoFile
          Else
          'display some Error Message to the User
          End If
          End If[/CODE]

          Comment

          • wassimdaccache
            New Member
            • Apr 2007
            • 222

            #6
            Originally posted by fnwtech
            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_plac e.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

            Comment

            • fnwtech
              New Member
              • Oct 2007
              • 48

              #7
              Originally posted by ADezii
              The code would be added to the Current() Event of the Form and would be similar to:
              [CODE=vb]
              'gPHOTO_PATH would be a Global Constant similar to:
              'Public Const gPHOTO_PATH As String = "\Photos\"
              'Photo Images would be stored in a Photos Directory under the
              'Current Project Path

              'Can be set in the Properties Window of the Image Control
              Me![imgPhoto].SizeMode = acOLESizeStretc h

              If IsNull(Me![txtPhotoFile]) Then 'No Picture File, display no Picture
              Me![imgPhoto].Picture = ""
              Else
              'Picture File listed, but does the Path and actual File exist?
              If Dir(CurrentProj ect.Path & gPHOTO_PATH & Me!txtPhotoFile , vbNormal) <> "" Then ' it exists
              Me![imgFieldInvento ry].Picture = CurrentProject. Path & gPHOTO_PATH & Me!txtPhotoFile
              Else
              'display some Error Message to the User
              End If
              End If[/CODE]

              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?

              Comment

              • wassimdaccache
                New Member
                • Apr 2007
                • 222

                #8
                Originally posted by fnwtech
                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
                Code:
                         Function GetPath()
                   'Returns the path to currently opened MDB or ADP
                   GetPath = CurrentProject.Path
                End Function
                then on your form on current action use VBA and write this code


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

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

                wassim s daccache
                CCE

                Comment

                • ADezii
                  Recognized Expert Expert
                  • Apr 2006
                  • 8834

                  #9
                  Originally posted by fnwtech
                  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:
                    [CODE=vb]Public Const gPHOTO_PATH As String = "\Photos\"[/CODE]
                  2. In the Current() Event of your Form, place this code:
                    [CODE=vb]
                    'Photo Images would be stored in a Photos Directory under the
                    'Current Project Path

                    'Can be set in the Properties Window of the Image Control
                    Me![imgPhoto].SizeMode = acOLESizeStretc h

                    'Name your Image Control imgPhoto
                    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(CurrentProj ect.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
                    End If
                    End If[/CODE]
                  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.

                  Comment

                  • fnwtech
                    New Member
                    • Oct 2007
                    • 48

                    #10
                    Originally posted by ADezii
                    1. In a Standard Code Module, place this Constant Declaration:
                      [CODE=vb]Public Const gPHOTO_PATH As String = "\Photos\"[/CODE]
                    2. In the Current() Event of your Form, place this code:
                      [CODE=vb]
                      'Photo Images would be stored in a Photos Directory under the
                      'Current Project Path

                      'Can be set in the Properties Window of the Image Control
                      Me![imgPhoto].SizeMode = acOLESizeStretc h

                      'Name your Image Control imgPhoto
                      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(CurrentProj ect.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
                      End If
                      End If[/CODE]
                    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!

                    Comment

                    • ADezii
                      Recognized Expert Expert
                      • Apr 2006
                      • 8834

                      #11
                      Originally posted by fnwtech
                      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.

                      Comment

                      • fnwtech
                        New Member
                        • Oct 2007
                        • 48

                        #12
                        Originally posted by ADezii
                        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?

                        Comment

                        • ADezii
                          Recognized Expert Expert
                          • Apr 2006
                          • 8834

                          #13
                          Originally posted by fnwtech
                          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.

                          Comment

                          • fnwtech
                            New Member
                            • Oct 2007
                            • 48

                            #14
                            Originally posted by ADezii
                            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 = acOLESizeStretc h

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

                            The object is a bound object frame.

                            Comment

                            • ADezii
                              Recognized Expert Expert
                              • Apr 2006
                              • 8834

                              #15
                              Originally posted by fnwtech
                              Okay, got that fixed, I just changed the image control to imgPhoto. Now when I launch, it stops at this line:
                              Me![photo].SizeMode = acOLESizeStretc h

                              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:
                              [CODE=vb ]Me![imgPhoto].SizeMode = acOLESizeStretc h[/CODE]

                              Comment

                              Working...