[ general remark: NEVER write code on forms, unless absolutely necessary. Write code in the source table, or in a (dedicated?) codeunit ]
What do you mean by 'purchase date' ? - is that the date that your customer purchased something from you, or is it the date that you purchased the item from your supplier?
I created a form using the sales invoice header and sales invoice line added 3 fields in main form i.e, customer no, from date and to date,and in sub form i taken the fields like item no,line no,document no,customer no, purchase date and to date. Now my task is to display the sales of an customer during the from date and to date..please say me how to filter the sales..
I presume that the date fields on the header are not actually fields in the sales invoice header. In this case you should probably need to do:
1. Create a function on your subform [so far for my 'general remark' ] with 2 parameters of type 'Date'. This function should have code something like:
2. Create a function on your main form that calls the function on your subform and provides the values of the date-fields that you added to this form. Code looks something like:
(I have no Classic Client available; I'm not sure about the location of '.FORM.' in this code)
3. Call this last function from the 'OnValidate' trigger of both date fields.
Some more remarks:
- are you aware of the fact that Sales Invoice records can be deleted after they are printed once? So your list might be incomplete.
- You miss returned / credited item information.
- Probably you should use the 'Item Ledger Entry' table to get your information. Records cannot be deleted from that table, and also returned items are in there. Also all fields that you need are available somehow in that table - without any modification necessary.
When you write code on a form, you can use CurrForm to access controls on that form from your code.
On your form is a subform; to be able to access the subform from your code you have to give the subform a name. The common name for the subform on a Sales main form is 'SalesLines' - but you should check which name it is in your case. [that is why you need to share more code and screenprints: so members on this forum can use the actual names for your case]
The FORM is a NAV construction to allow you to access code that is actually on your subform.
MyFilterFunction is the name of the function that you create on the subform. FromDate and ToDate shoule be replaced by the actual names of the variables that you added to the main form.
Answers
What do you mean by 'purchase date' ? - is that the date that your customer purchased something from you, or is it the date that you purchased the item from your supplier?
1. Create a function on your subform [so far for my 'general remark' ] with 2 parameters of type 'Date'. This function should have code something like: 2. Create a function on your main form that calls the function on your subform and provides the values of the date-fields that you added to this form. Code looks something like: (I have no Classic Client available; I'm not sure about the location of '.FORM.' in this code)
3. Call this last function from the 'OnValidate' trigger of both date fields.
Some more remarks:
- are you aware of the fact that Sales Invoice records can be deleted after they are printed once? So your list might be incomplete.
- You miss returned / credited item information.
- Probably you should use the 'Item Ledger Entry' table to get your information. Records cannot be deleted from that table, and also returned items are in there. Also all fields that you need are available somehow in that table - without any modification necessary.
CurrForm.SalesLines.FORM.MyFilterFunction(FromDate,ToDate); ??
Need help
On your form is a subform; to be able to access the subform from your code you have to give the subform a name. The common name for the subform on a Sales main form is 'SalesLines' - but you should check which name it is in your case. [that is why you need to share more code and screenprints: so members on this forum can use the actual names for your case]
The FORM is a NAV construction to allow you to access code that is actually on your subform.
MyFilterFunction is the name of the function that you create on the subform. FromDate and ToDate shoule be replaced by the actual names of the variables that you added to the main form.