RATING: Advanced
PLATFORM: Macintosh & Windows
VERSION: FileMaker 4/5
TECHNIQUE FILES: CalendarYear.fp5
It's the little things that matter
One of the most amazing things about FileMaker is all of its hidden capabilities. Time after time you find yourself anguishing over that one feature you wish it had. However, sometimes it's just a matter of knowing what can and can't be done with the software. One of those little, but powerful, things is the ability to copy a full layout when in Preview mode - regardless of the layout size.
With a little ingenuity you can accomplish a number of powerful tasks such as document archival and more complex printable forms. Just to get you started I'd like to propose a challenge. Take a moment and try to envision how you would accomplish the creation of a printable calendar that contains all of the months of the year on one single page - and doing it with FileMaker.
Of course, I'm going to be showing you how I did it using only two layouts and essentially one script, aside from the necessary calculations and fields used to generate the calendar. But before you figure it out, by reading the rest of this article, give your brain a short pause and spend a few cycles thinking about the solution. This one will please you.
Understanding the basics
The best way to understand this solution is to know what's possible when you enter into Preview mode. Simply put, you can copy the layout and it lands on the clipboard as a picture. This means you can now do whatever you want with that picture including pasting it into a container field where it can be saved.
To accomplish the creation of a yearly calendar within the Calendar.fp5 file I needed two layouts. One of the layouts is used exclusively for copying the layout when in preview mode. Understandably, in order to fit all twelve months onto one 8 1/2 X 11 sheet of paper I need their size to be small enough to fit side by side so FileMaker can print them in columns running across the page.
So the first step was to make a mini version of the calendar. I did this by simply shrinking everything down using the Object Size palette while viewing things at 400%. After this I knew the copied calendar would be pasted into the container field and the default container field would be set to reduce the graphic. The solution to this problem came in two steps. The first was knowing that the calendar would be centered in the container field. This meant I needed to center the calendar on the page so that when copied and pasted, the container field would be centered. The last part was to set the formatting for the container field to crop the picture leaving all of the unnecessary white area surrounding the copied calendar cut off. (see figure 2)
(Developer note:
By jumping back and forth between the two layouts, one with the preview of the Mini Calendar, named Mini View, and the Year View I was able to cycle through the months in my script and simply move from one record to the next.
Understanding the complexity
And now we start the good stuff. With one single script I was able to create a looping routine that would account for many of the possible states the file might be in. The first test is for the number of records. Knowing there are twelve months in the year I only needed twelve records. The first part of the script addresses this. Take a look at the script before I explain the rest.
Set Error Capture [ On ]
# "This file only uses Global fields and Calculations so it's ok to run routines that control the number of records in the file.
So long as one record is left in the file when you close it."
Enter Browse Mode
Show All Records
# "If more than 12 records delete some"
If [ Status(CurrentRecordCount) > 12 ]
Loop
Delete Record/Request
[ No dialog ]
Exit Loop If [ Status(CurrentRecordCount) = 12 ]
End Loop
Else
# "If fewer than 12 records create some"
If [ Status(CurrentRecordCount) < 12 ]
Loop
New Record/Request
Exit Loop If [ Status(CurrentRecordCount) = 12 ]
End Loop
End If
End If
# "------------------------------"
# "Set in the Months of the Year"
Set Field [ Workspace, "January" & "¶" &
"February" & "¶" &
"March" & "¶" &
"April" & "¶" &
"May" & "¶" &
"June" & "¶" &
"July" & "¶" &
"August" & "¶" &
"September" & "¶" &
"October" & "¶" &
"November" & "¶" &
"December" ]
Go to Record/Request/Page [ First ]
# "Cycle through the months striping them off."
Freeze Window
Loop
Exit Loop If [ IsEmpty(Workspace) ]
Set Field [ Month , LeftWords(Workspace, 1) ]
Go to Layout [ Mini View ]
Enter Preview Mode
Copy []
Enter Browse Mode
Go to Layout [ Year View ]
Paste [ Mini Calendar ]
[ Select entire contents ]
Go to Record/Request/Page
[ Next ]
Set Field [ Workspace , Right(Workspace, Length(Workspace) - Length(LeftWords(Workspace, 1)) - 1) ]
End Loop
# "------------------------------"
# "Now print the layout"
Perform Script [ " Page Setup 8.5 X 11 (Multiple)" ] [ Sub-scripts ]
Print
Go to Layout [ original layout ]
Using a strip method of working with the month values, I am able to avoid having to use a counter value to cycle through the months. The first step after preparing the database with exactly twelve records is to set a global field named Workspace to contain a return delimited list of values for each of the month names.
After setting the month names, the rest of the script is simply a matter of looping through the values and jumping back and forth from the layout used to copy and pasting the copied layout into the container field on the layout formatted for a three column printable form.
Because the top value of the return delimited list is stripped off I use an Exit Loop step detecting if the field is empty after it has used the last value in the list.
After the whole loop has cycled through each month then it's just a matter of setting up your page and printing out your wonderful new yearly calendar.
Understanding the power
Hopefully, by going through this article and the file it discusses, you will see the power in using Copy Preview to accomplish a number of things related to your database system. This little known trick can be used to keep a catalog of printed invoices, monitor what users are printing, create more complex forms showing data from other files without needing a relationship and so on. If you come across more uses for this technique then by all means send them in and we'll credit you with all the glory!
Happy FileMaking!
Matt Petrowsky is Founder and President ISO Productions, Inc. Since 1994, ISO has provided many of the industry's top FileMaker Pro resources, including the Everything CD for FileMaker Pro, ISO FileMaker Magazine, "Scriptology: FileMaker Pro Demystified" Book and CD-ROM, and the ultimate training resource, Scriptology Developer's Toolkit. Most recently, Mr. Petrowsky has created the licensed solution FileMaker Solution Framework distributed by FileMaker, Inc. His favorite past times include spending time with his favorite person, his wife, and motorcycle riding around the hills.