Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Increasing months on new invoice lines 1

Status
Not open for further replies.

123FakeSt

IS-IT--Management
Aug 4, 2003
182
My first week in Crystal formulas (sorry for the lack of braces ... i'm a VB guy)

I am trying to get the lines on this invoice to create a month description in this fashion:

The first set of lines displays the description of the next month (a 10/1/05 invoice will display "November 2005")

When the next set of lines begins (the first {ARTran.TaxCat} will repeat) it will move on to "December 2005" until the group is done.

This isn't working :(

Code:
NumberVar Sequence;
StringVar initProd;
NumberVar MonthCount;

Sequence := Sequence + 1;
If Sequence = 1 Then StringVar initProd = {ARTran.TaxCat};
If Sequence = 1 Then MonthCount = 1;
If Sequence > 1 Then If {ARTran.TaxCat} = initProd Then MonthCount = MonthCount + 1;
MonthName(Month({ARDoc.DocDate})+ MonthCount) & " " & ToText(Year(DateAdd("m",1,{ARDoc.DocDate})),"0000");


The early bird gets the worm, but the second mouse gets the cheese.
 
Rather than using "next set of lines" as your descriptive, try to use technical terms, such as what section the formula is in, as in the Details section.

Successful posts generally include basic technical information, as in:

Crystal version (every tech support persons 1st question)
Database/connectivity used
Example data
Expected output

Rather than dictation how you want to do something, show the data and the requirements and ask for solutions.

-k
 
In the Group#1 Detail I have:

a
b
c
a
b
c

Or sometimes:
a
b
a
b

And I need to create (for any combination of letters):

a November 2005
b November 2005
a December 2005
b December 2005
a January 2006
b January 2006

It is important to note that 'a' could be any value so I need to store it during the running logic.

The early bird gets the worm, but the second mouse gets the cheese.
 
There isn't a Group 1 Detail section, there's a Group 1 and a Detail section.

Note what I asked you to post, and what you posted.

I understand that you're busy, but posting example DATA is a basic requirement. How would A, B, etc relate to a date?

-k

 
A, B and C have no relation to a date. There are text descriptions.

For example you could have:
apple
pear
orange
apple
pear
orange
apple
etc...

I need to increment the date by one month at each occurence of 'apple'

The next group header will of course reset the date

I can't even manage to get the Sequence to increment in this example.

Code:
WhilePrintingRecords

Dim Sequence as Number
Dim initProd as String
Dim MonthCount as Number

Sequence = Sequence + 1
If Sequence = 1 Then initProd = {ARTran.TaxCat}
If Sequence = 1 Then MonthCount = 1
If Sequence > 1 Then If {ARTran.TaxCat} = initProd Then MonthCount = MonthCount + 1

Formula = Sequence
'Formula = MonthName(Month({ARDoc.DocDate})+ MonthCount) & " " & ToText(Year(DateAdd("m",1,{ARDoc.DocDate})),"0000")[\code]

Sorry i'm frustrating you.  I've posted many times (and replied to others) and never had a problem conveying my intentions.

The early bird gets the worm, but the second mouse gets the cheese.
 
Using your last example, try:

whileprintingrecords;
numbervar seq1;
numbervar seq2;
datevar monthx := date(2005,02,01);//date of starting month

if {table.fruit} = "Apple" then //reset value
seq1 := 1 else
seq1 := seq1 + 1;
if {table.fruit} = "Apple" then
(
seq2 := seq2 + 1;
monthx := date(dateadd("m",seq2,monthx))
) else
(
seq2 := seq2;
monthx := date(dateadd("m",seq2,monthx))
);
monthname(month(monthx))+" "+ totext(year(monthx),"0000")

-LB
 
Thanks LB ... all is well except that I am having a problem storing the initial 'Apple' because it could be anything (indicated in the bold).

How do I store the initial value for use later in the code?

Like .. 'if this is the first line, store value'
Code:
whileprintingrecords;
numbervar seq1;
numbervar seq2;
datevar monthx := CDate({ARDoc.DocDate});//date of starting month
[b]stringvar product := {ARTran.TaxCat};[/b]

if {ARTran.TaxCat} = product then //reset value
seq1 := 1 else
seq1 := seq1 + 1;
if {ARTran.TaxCat} = product then
(
seq2 := seq2 + 1;
monthx := date(dateadd("m",seq2,monthx))
) else
(
seq2 := seq2;
monthx := date(dateadd("m",seq2,monthx))
); 
monthname(month(monthx))+" "+ totext(year(monthx),"0000")

I reset the seq between invoices like this but I can not access the detail from the group level I don't think.

Code:
WhilePrintingRecords;
NumberVar seq1 := 0;
NumberVar seq2 := 0;

This was my attempt, but now it never increases.

Code:
whileprintingrecords;
numbervar seq1;
numbervar seq2;
datevar monthx := CDate({ARDoc.DocDate});//date of starting month
stringvar product;

if seq1 = 0 then product = {ARTran.TaxCat};

if {ARTran.TaxCat} = product then //reset value
seq1 := 1 else
seq1 := seq1 + 1;
if {ARTran.TaxCat} = product then
(
seq2 := seq2 + 1;
monthx := date(dateadd("m",seq2,monthx))
) else
(
seq2 := seq2;
monthx := date(dateadd("m",seq2,monthx))
); 
monthname(month(monthx))+" "+ totext(year(monthx),"0000")

The early bird gets the worm, but the second mouse gets the cheese.
 
Use this as your reset formula in the invoice group header:

whileprintingrecords;
numbervar seq1 := 0;
numbervar seq2 := 0;
stringvar product := "";
numbervar cnt := 0;

Then change the formula to:

whileprintingrecords;
numbervar seq1;
numbervar seq2;
datevar monthx;
stringvar product;
numbervar cnt := cnt + 1;

if cnt = 1 then
(
product := {ARTran.TaxCat}; //reset value
monthx := CDate({ARDoc.DocDate}) //starting month
);
if {ARTran.TaxCat} = product then
seq1 := 1 else
seq1 := seq1 + 1;
if {ARTran.TaxCat} = product then
(
seq2 := seq2 + 1;
monthx := date(dateadd("m",seq2,monthx))
) else
(
seq2 := seq2;
monthx := monthx);
monthname(month(monthx))+" "+ totext(year(monthx),"0000");

-LB
 
Thanks a bunch LB. I think i'm starting to catch on (needing the variables set up a level higher to use them in the detail). That solution worked exactly.

I wouldn't have figured that out for hours!

123FakeSt

The early bird gets the worm, but the second mouse gets the cheese.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top