5 Replies Latest reply on Jul 4, 2012 10:50 AM by philmodjunk

    Printing most recent labels

    RashinAlizadeh_1

      Title

      Printing most recent labels

      Post

       Hi,

      I have a database that can also print labels based on the info in the database.

      However, new information is always entered that needs to have the relevant labels printed. So I want to write a script that will allow the user to print labels for the most recent data entered.

      I have a layout for the data entry

      I have a layout for the labels that gets its info from the above layout.

      I tried writing a script that shows a dialog box where the user can enter the date range (representing the creation date of the files) of the files that they want printed. However, I am having trouble writing this script. Instead of the user entering these dates, is there a way for filemaker to remember the last print date, and just print labels for everything after that date?

      Thanks

        • 1. Re: Printing most recent labels
          philmodjunk

          I have a layout for the labels that gets its info from the above layout.

          Techincally, one layout cannot get its info from another layout. They can, however, refer to the same table where this data was stored.

          If you want assistance with that script feel free to post what you are attempting to create and we can help you with it.

          If you use a script to print the labels, the script can record the current date in a global field or a record in a related file. A global field works if you have a single user database. Use a record in a related table if it is hosted over a network so more than one user can access it at a time.

          Your script to find records created since the last label print job might look like the following example. It assumes that you ahve a date field that auto-enters the date the records was created.

          Set Variable [$DateLastPrint ; value: PrintLog::Date ]
          Go to Layout [Labels (YourTable) ]
          Enter Find Mode []
          Set field [Yourtable::DateCreated ; ">"&$DateLastPrint]
          Set ErrorCapture [on]
          Perform Find []
          IF [Get ( FoundCount ) //records were found]
              Print
              Set Field [PrintLog::Date ; Get ( CurrentDate ) ]
          Else
              Show Custom dialog ["No records created since " & $DateLastPrint & " were found."]
          End If
          Go to Layout [original layout]

          Names in Blue are names of items defined in your database file. Use your names in place of those used here. Items in Red refer to specific FileMaker supplied items already present in every database file.

          • 2. Re: Printing most recent labels
            RashinAlizadeh_1

             Ok so I am a bit lost with the since last print script:

            I got stuck on the first line :-/

            which ones are actual calculation codes (found in the functions list of commands) and which are ones that I need to have tables/fields for?

            Where does the printLog::Date come from?

            I also do not understand the DateLastPrint. Does Filemaker have a function for that already?

            Thanks

            • 3. Re: Printing most recent labels
              philmodjunk

              PrintLog would be a table you define in your database with a field named Date. (and you can use different names if you want.)

              You'd link it to your current table like this:

              YourTable::anyfield X PrintLog::anyfield

              You'd need to use a script to print your labels and it would have this step in it:

              Set Field [PrintLog::Date ; Get ( CurrentDate ) ]

              $DateLastPrint is a variable. Note the dollar sign that is a required part of its name. The script copies the date from PrintLog::Date into this variable because the data in non-global fields are not accessible once the script enters find mode, but the data in a variable is accessible. To understand this, take any layout in your database and click the Find button to enter Find Mode. Note how all but global fields are now blank. This happens in the script as well and this is why we copy the date into the $DateLastPrint variable.

              I'm going to edit my post with the sample script. Items within the [square brackets] shown in red are FileMaker supplied identifiers you can look up in Filemaker help if you need to learn more. Items shown in Blue will be table, field, variable, or layout names you would need to have in your database. Since I don't know the names of the actual items in your database, I made up names to use in the example. You can subsitute your names for mine and only add new items where you don't have such items already defined in your database file.

              • 4. Re: Printing most recent labels
                RashinAlizadeh_1

                 Ok so thank you for clarifying. However, there is something wrong with what I have written, because it still keeps saving all of them without saying that there are no new records.

                I am actually saving it to PDF (then manually printing) as opposed to a straight print through the script. The scipt does not save the date of the new print (save as PDF) in the Date field of PrintLog, which means I am doing something wrong. I think it is with the way I have connected the two tables. I thought you could only link two fields in different tables, how would I do

                YourTable::anyfield X PrintLog::anyfield

                Here is what I have, with the names I use:

                Set Variable [$DateLastPrint ; value: PrintLog::Date ]
                Go to Layout [File Folder Labels (Enter Filing Data) ]
                Enter Find Mode []
                Set field [Enter Filing Data::Date Modified ; ">"&$DateLastPrint]
                Set ErrorCapture [on]
                Perform Find []
                IF [Get ( FoundCount ) //records were found]

                Save Records as PDF
                        Set Field [PrintLog::Date ; Get ( CurrentDate ) ]
                Else
                    Show Custom dialog ["No records created since " & $DateLastPrint & " were found."]
                End If
                Go to Layout [original layout]

                • 5. Re: Printing most recent labels
                  philmodjunk

                  What relationship do you have? Did you create an initial record in PrintLog? Unless you enter a date into the PrintLog::Date field manually, it will generate a PDF of all the labels in the table, but will not do it the next time as long as that date gets recorded in the PrintLog table.

                  I thought you could only link two fields in different tables, how would I do

                  YourTable::anyfield X PrintLog::anyfield

                  This is a link between two fields in different tables so I'm not sure that I understand that question.

                  You Open Manage | Database and use the tables tab to create a new table. I named it PrintLog in this example.

                  Then you use the fields tab to define at least a date field. I called it "date".

                  Then click on the relationships tab and drag from any field in your original table (what I have called "your table"), to any field in PrintLog. This establishes a relationship between the two tables, but with the default = operator. Double click the line between the two to open a dialog where you can change the = into the cartesian join operator (X). This operator matches any record on one side of the relationship to all records on the other side of the relationship.

                  Now click OK to close Manage | Database. Go to the layout for PrintLog and choose New Record from the records menu. If you wish, you can enter a date in the date field as the date of the labels last printed.

                  Now your script should work.