9 Replies Latest reply on Dec 3, 2010 10:38 AM by philmodjunk

    Insert Picture only if filename contains words in specific fields

    basumaiku

      Title

      Insert Picture only if filename contains words in specific fields

      Post

      Hi Everyone,

      I'm new to FileMaker. Here's my current situation:

      I have a folder of pictures. These are photos of people, and their names are written in caps as the picture's filename (for example, "JOHN DOE.jpg"). I'd like to import these pictures into their respective container fields within a table, but only when the filename contains the same words as those written in the "First Name" and "Last Name" fields, so I don't end up with records of people with the wrong photo. Moreover, I want to keep the "First Name" and "Last Name" fields as they are, I do NOT want to replace those fields with the filename of the picture.

      Can anyone help me with this?

        • 1. Re: Insert Picture only if filename contains words in specific fields
          philmodjunk

          Use Import Records | Folder into a separate table. You have the option to capture the file names in a separate field during the import.

          Now use the filename in the picture table to link this record to the correct record in your original table.

          I'd do it this way:

          Define a serial number field, PictureID, in the image table so that each picture record has a unique ID.
          Define a calculation field in your original table, cFileName as FirstName & LastName & ".jpg"
          Define a relationship linking your tables by cFileName in your original table to the Filename field in the picture table.
          Define a PictureID field in your original table and place it on a layout based on your original table.
          Show all records in your original table
          Put the cursor in PcitureID and select Replace Field Contents.
          Select the calculation option and enter this calculation: YourPictureTable::PictureID and perform the replace.
          Define a relationship that links your picture table and original tables by PictureID. Use this relationship, not the one based on names whenever you want to place a picture on a layout based on your original table.

          • 2. Re: Insert Picture only if filename contains words in specific fields
            basumaiku

            Hi PhilModJunk,

            Thank you for the help. I was following your instructions up until the last part:

            "Define a relationship that links your picture table and original tables by PictureID. Use this relationship, not the one based on names whenever you want to place a picture on a layout based on your original table."

            Both the PictureID field of my picture table and the PictureID field from my original table are gray while in Relationships, I can't make the relationship. Trying to figure out where I went wrong...

            Also, will FirstName & LastName & ".jpg" work if there is a space between FirstName and LastName or does everything have to match up exactly as the calculation is written (with no spaces included). I'd like it to work if it merely contains the FirstName and LastName, and then if it is either a .jpg or .bmp

            Thank you again for all of you help!

            • 3. Re: Insert Picture only if filename contains words in specific fields
              basumaiku

              Oh yeah, I forgot to mention, I was able to replace the field contents, but they still didn't show up. I just figured I still couldn't see the pictures because I couldn't define the relationship between the two container fields...

              Thank you again!

              • 4. Re: Insert Picture only if filename contains words in specific fields
                basumaiku

                Actually, just messing around with the portal tool, I was able to get the PictureID field to appear on the original layout. However, the last record doesn't show up for some reason. 

                Pardon the bombardment of replies! Just trying to figure all of this out.

                • 5. Re: Insert Picture only if filename contains words in specific fields
                  philmodjunk

                  Both the PictureID field of my picture table and the PictureID field from my original table are gray while in Relationships, I can't make the relationship.

                  What version of FileMaker are you using? Both PictureID fields should be number fields. The one in your image table should be an auto-entered serial number. When importing the images make sure that you select the "Auto-Enter" option so that the serial numbers are assigned during import. If you get them imported and this field is still empty, you won't be able to link the image records to records in your main table. If this happens, you can use Replace Field Contents with the serial number option to correct the omission.

                  Also, will FirstName & LastName & ".jpg" work if there is a space between FirstName and LastName or does everything have to match up exactly as the calculation is written (with no spaces included). I'd like it to work if it merely contains the FirstName and LastName, and then if it is either a .jpg or .bmp

                  The text produced by this calculation has to be a letter for letter match to the filename of the imported image it is to link to. So don't include a space unless the filename also has a space between first and last names. Since you mention two different file extensions, here's a more sophisticated calculation for cFileName that will enable you to match to filenames of either extension:

                  List ( FirstName & LastName & ".jpg" ; FirstName & LastName & ".bmp" )

                  • 6. Re: Insert Picture only if filename contains words in specific fields
                    basumaiku

                    I'm using FM 11. Ok, now I've got the PictureID field in the picture table showing the automated serial number. Both PictureID fields are now number fields (I started over the process from the beginning to be sure). I created a relationship between the PictureID field in the picture table and the PictureID field in the original table, but the PictureID field in the original table still doesn't show anything (not a picture, not even a serial number).

                    • 7. Re: Insert Picture only if filename contains words in specific fields
                      philmodjunk

                      Have you already imported the pictures into this table?

                      • 8. Re: Insert Picture only if filename contains words in specific fields
                        basumaiku

                        No, not into the PictureID field in the original table. I've only imported the images (or rather, their auto-assigned serial numbers) into the second picture table...

                        • 9. Re: Insert Picture only if filename contains words in specific fields
                          philmodjunk

                          I'm not sure I follow that. Let's call your original table "Personnel" and your table of pictures "Images"

                          Have you imported your folder of picture files into Images?

                          Do each of these records show a serial number in their ID field?

                          You should have these two relationships between personnel and images:

                          Personnel::cFileName = Images::FileName

                          Personnel::ImageID = Images 2::ImageID

                          If you place the container field from Images (not images 2) on your personnel layout, do you see the person's picture like you expect? (This confirms that cFileName is correctly matching to an Images record by file name.)

                          If so, then you can Show all records, then Click into the ImageID field in Personnel and use Replace Field Contents to copy the matching image record's ID number into this field for every record. Once you have done this, you can replace the container field from Images with the container field from Images 2.