Link to home
Start Free TrialLog in
Avatar of j_rameses
j_ramesesFlag for United States of America

asked on

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

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?
Avatar of Member_2_908359
Member_2_908359
Flag of France image

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?
Avatar of j_rameses

ASKER

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
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?
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.
variable = MonthName(Date(Month( Get ( CurrentDate) ) + 1;Day(Get ( CurrentDate));Year(Get ( CurrentDate))))
where do I create the variable & what type of field is it?text?calc?
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.
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?
That's great, put it in there.  

To clear the global field, just do:  

Set Field [ <your global field's name> ] = ""
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 & "/*"
Also, how do I clear the global field at the end of the script?
set global field = ""
SOLUTION
Avatar of Tocacar
Tocacar
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the global field has an advantage in case you'd like to use to filter a portal
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?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?
Yes.
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]
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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"
     
I could only make it look like:
Set Field [@_Globals::NextMonth]; $myVariable
How do I get the button to display the value of @_Global::NextMonth + whatever other wording i want?
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.
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.
It can, as described in my most recent post.
oops sorry I should read more carefully