[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

How do I in Filemaker create a script to find next months month name?

Posted on 2010-04-07
29
Medium Priority
?
556 Views
Last Modified: 2012-05-09
I am running FileMaker 10.
I created a button that when clicked it should search a table with the field called "BdayMonth".
The script should use the next month and compare it to the field "BdayMonth" and display those names.
Right now the script that runs when the button is clicked is:
New Window
Goto layout
Set Variable [$NextMonth; Value:_Contacts::cc_NextMonthDayMonth]
Enter Find mode []
Set Field[_Contacts::bDayMonth; $NextMonth]
Perform Find[]
Enter Preview Mode[]
Print Setup[Restore]
Print[Restore]
CLose Window[Current Window]
---------------------------------------------------

On "Contacts" table I have a field called:"cc_NextMonthBdayMonth" it holds the following calculation:
MonthName(MonthsAhead((Get(CurrentDate));1))
---------------------------------------------------
The "MonthName" is a custom function.  The code is:
Let(
   [guess = Date(Month(NextMonth) + months; Day(NextMonth); Year(NextMonth));
   expectedMonth = Mod(Month(NextMonth) + months - 1; 12) + 1];

   If ( Month(guess) = expectedMonth; guess; Date(Month(NextMonth) + months + 1; 1; Year(NextMonth)) - 1 )
)

Where I created the parameters: "NextMonth" & "months"
----------------------------------------
The code worked for the month of March when it was clicked it displayed the records that the month was "April" in the field "bDayMonth" in the "Contacts" table.
But now in the month of "April" when I click onthe button, it still displays the records for "April".

How do I create the correct code or fix this?
0
Comment
Question by:j_rameses
  • 14
  • 10
  • 5
29 Comments
 
LVL 28

Expert Comment

by:lesouef
ID: 30098038
woh, rather complex for what it does? what's the goal here? show records with a date of which the month is the next one (from today)?
and what is months? and monthsahead?
0
 

Author Comment

by:j_rameses
ID: 30112019
Yes, I need it to when clicked gather all the records that the month is the next month so we can print out labels to mail them a birthday card.
Months ahead is a function. the code is above it is:
Let(
   [guess = Date(Month(NextMonth) + months; Day(NextMonth); Year(NextMonth));
   expectedMonth = Mod(Month(NextMonth) + months - 1; 12) + 1];

   If ( Month(guess) = expectedMonth; guess; Date(Month(NextMonth) + months + 1; 1; Year(NextMonth)) - 1 )
)
-----
I accidently said that the name of the functions is : monthName
0
 
LVL 28

Expert Comment

by:lesouef
ID: 30112537
I don't know what is "months", but this is weird to me as I understand that if the month of guess is the expected one, you keep the guess date, and if not, you pick up the next month date. what for? do I miss something? who made this function? do you have the equiv in human language?
is that supposed to get the next month name? or more?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:j_rameses
ID: 30113451
What I need the code to do is that when ever the user clicks on the birthday card button is to make a variable the value of the next month.  Then that value will be compared to all records to search in the "bDayMonth" field of the "Contacts" table to search for the value of the variable that is the next month.  For example, say we are in the month of April.  The variable should retrieve the value of "May".  I need a variable with that value because I have two other scripts that use that value.  So when the button is clicked it will look for any record that has the value of "May" in the "bDayMonth" field from the "Contacts" table.  If we are in the month of May, it should pull up the records that the birth month is June.  That is what I need it to do.
0
 
LVL 8

Expert Comment

by:Tocacar
ID: 30114998
variable = MonthName(Date(Month( Get ( CurrentDate) ) + 1;Day(Get ( CurrentDate));Year(Get ( CurrentDate))))
0
 

Author Comment

by:j_rameses
ID: 30115132
where do I create the variable & what type of field is it?text?calc?
0
 
LVL 8

Expert Comment

by:Tocacar
ID: 30115536
Make a global text field and store the value in that as part of the script, then in the 'Enter Find Mode / Set Field ....' section you can use the global field to set the search criteria in the Set Field step.  Remember to clear the global field at the end of the script.

As it's a *global* text field, you can put this in any table you like and you will be able to grab the value in it regardless of which layout (table occurrence context) you are on.
0
 

Author Comment

by:j_rameses
ID: 30115762
we have a table called "@_Global".
Can I put it there?
Also, how do I clear the global field at the end of the script?
0
 
LVL 8

Expert Comment

by:Tocacar
ID: 30116008
That's great, put it in there.  

To clear the global field, just do:  

Set Field [ <your global field's name> ] = ""
0
 
LVL 28

Expert Comment

by:lesouef
ID: 30117548
why do you want to store it?
the var is text, always in fm. to calc its value, use tocacar's formula whihc is correct.
you can use it directly by searching the date field in contacts=
$var & "-*-*"
if - is you regional date separator with the US date format.
change this  if you use another format. European french format would be:
"*/" & $var & "/*"
0
 

Author Comment

by:j_rameses
ID: 30117804
Also, how do I clear the global field at the end of the script?
0
 
LVL 28

Expert Comment

by:lesouef
ID: 30117838
set global field = ""
0
 
LVL 8

Assisted Solution

by:Tocacar
Tocacar earned 2000 total points
ID: 30118626
lesouef:  I thought that also, but then I thought he may be better off storing the value in a global field as he says he uses the currentmonth+1 value in two other scripts.

j_rameses:  Don't worry about clearing the global field - I see above that you want to use this value again in other scripts.  The best time/ place to save this value in the global field would be as part of a script that runs automatically when a user logs in.  The script (call it 'login' if you like) should have the following steps:

set variable $myvariable = use the calc I provided above
set Field [<my global field>] = $myvariable

To have this script run automatically whenever someone logs in, go to File/ File Options and select the script to run at login (the settings to select are obvious).

You will now be able to access this value throughout the user session, and use it in any script you like.

An alternative to using a global field is to instead just create a global variable.  You do this using two "$" signs in front of the variable name:

$$myvariable  (is global)
$myvariable    (is local)

Either option will suit your purposes just fine, but if you go the global variable route, remember to always have 2 dollar signs ($$) in front of the variable name.




0
 
LVL 28

Expert Comment

by:lesouef
ID: 30119224
the global field has an advantage in case you'd like to use to filter a portal
0
 

Author Comment

by:j_rameses
ID: 30119807
So, in the "@_Global" table I should use the field "cc_NextMonth" and enter the following calculation:
variable = MonthName(Date(Month( Get ( CurrentDate) ) + 1;Day(Get ( CurrentDate));Year(Get ( CurrentDate))))
Where variable is equal to my "cc_NextMonth"?
-----------------------
Then my script which is called: Next Month B-day Card" has the following code?:
New Window [Name: @_Global::cc_NextMonth & "'s Birthday Mailing Card List"; Height:850; Width:.....]
Goto layout
Set Variable [$NextMonth; Value: @_Global::cc_NextMonth ]
Enter Find mode []
Set Field[_Contacts::bDayMonth; $NextMonth]
Perform Find[]
Enter Preview Mode[]
Print Setup[Restore]
Print[Restore]
CLose Window[Current Window]

Is that what the code should look like for the script?
0
 
LVL 8

Accepted Solution

by:
Tocacar earned 2000 total points
ID: 30120284
You're almost there.  It's just a little bit scrambled.

1.  Make a brand new global field, stored your global table, called 'NextMonth' (this is a text field set to have global storage).  You are going to use this field in your scripts.

2. Make a script called 'Log In Script' with the following two steps:

set variable $myvariable = use the calc I provided above
set Field [<my global field>] = $myvariable

If you already have a script set to run at login, just include these two steps in it.  If you don't already have a script set to run at login, create one, as mentioned above, and then go to File/ File Options and select it to run when the file is opened (i.e., when the user logs in); the settings to choose are obvious.

2.  With that done, close the file, then log back in.  Your global field 'NextMonth' now has the name of next month stored in it.

3.  Now, modify your script as follows:

New Window [Name: @_Global::NextMonth & "'s Birthday Mailing Card List"; Height:850; Width:.....]
Goto layout
Enter Find mode []
Set Field[_Contacts::bDayMonth; @_Global::NextMonth]
Perform Find[]
Enter Preview Mode[]
Print Setup[Restore]
Print[Restore]
CLose Window[Current Window]

4.  Voila!
0
 

Author Comment

by:j_rameses
ID: 30121330
Let me disect this:
set variable $myvariable = use the calc I provided above
set Field [<my global field>] = $myvariable

$myvariable = use that name or come up with my own?
-------------------------------
use the calc I provided above = MonthName(Date(Month( Get ( CurrentDate) ) + 1;Day(Get ( CurrentDate));Year(Get ( CurrentDate))))
--------------------------------
[<my global field>] = should this be a different name i create or is it "NextMonth" & do i have to use the "<>" symbols
0
 
LVL 8

Assisted Solution

by:Tocacar
Tocacar earned 2000 total points
ID: 30121590
$myvariable = use that name or come up with my own?  
 
        -  by all means, feel free to choose, it's not important.  I simply used that as an obvious way to refer to it during the example

use the calc I provided above = MonthName(Date(Month( Get ( CurrentDate) ) + 1;Day(Get ( CurrentDate));Year(Get ( CurrentDate))))
       
       -  correct

[<my global field>] = should this be a different name i create or is it "NextMonth"
 
       -  once again, feel free to choose, it isn't import.  I was simply illustrating the example.  Giving it another name will not make it work any differently.

 & do i have to use the "<>" symbols

      -  no, this was just my way of encapsulating the field name to make it *stand out* from the rest of the text.




0
 

Author Comment

by:j_rameses
ID: 30123314
Lets say <my global field> i will call "theFollowingMonth"
where will I use this "theFollowingMonth"?
Is this the one I will use on my other two scripts?
0
 
LVL 8

Expert Comment

by:Tocacar
ID: 30123385
Yes.
0
 

Author Comment

by:j_rameses
ID: 30125135
I am on the creating script page.
I have:
Set Variable [$myVariable; Value:MonthName(Date(Month( Get ( CurrentDate) ) + 1;Day(Get ( CurrentDate));Year(Get ( CurrentDate))))]
Set Field [@_Globals::NextMonth]
0
 
LVL 8

Assisted Solution

by:Tocacar
Tocacar earned 2000 total points
ID: 30125224
Change:  

Set Field [@_Globals::NextMonth]

To:

Set Field [@_Globals::NextMonth] = $myVariable

Then you will have the name of next month stored in the global field.
0
 

Author Comment

by:j_rameses
ID: 30125761
oops i hit the submit button.
i continuation to the above:
               set Field [@-Globals::NextMonth] = $myvariable
Where do I put the value "$myVariable"?
Do I click on "CaLCULATED Result" button and enter the value "$myVariable"
     
0
 

Author Comment

by:j_rameses
ID: 30125852
I could only make it look like:
Set Field [@_Globals::NextMonth]; $myVariable
0
 

Author Comment

by:j_rameses
ID: 30130491
How do I get the button to display the value of @_Global::NextMonth + whatever other wording i want?
0
 
LVL 8

Expert Comment

by:Tocacar
ID: 30131432
I don't understand your apparent confusion.  You are asking questions about script steps that are already familiar to you, as you demonstrate in your original question.  

To display the value of the global field on the button, in Layout Mode, go to Insert/Merge Field and select the global field from the list.  You can add any other text you want by simply typing it, using the keyboard.

You now have all the information you need to complete your task.
0
 

Author Comment

by:j_rameses
ID: 30131797
I forgot to mention, I figure it out before your response.
I am only wondering if a button can have the text in it change to the value of "NextMonth"?
I did it for the tooltip and it works.
0
 
LVL 8

Expert Comment

by:Tocacar
ID: 30131854
It can, as described in my most recent post.
0
 

Author Comment

by:j_rameses
ID: 30132022
oops sorry I should read more carefully
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Conversion Steps for merging and consolidating separate Filemaker files The following is a step-by-step guide for the process of consolidating two or more FileMaker files (version 7 and later) into a single file with multiple tables. Sometimes th…
Problem: You have a hosted FileMaker database and users are tired of having to use Open Remote or Open Recent to access the database. They say, "can't you just give us something to double-click on rather than have to go through those dialogs?" An…
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Suggested Courses
Course of the Month11 days, 2 hours left to enroll

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question