Pass form variables to function in subform.

zulqzulq Member Posts: 204
Hi,
I created a form and sub form using employer and employee tables. On the form I have five variables that I want to pass to the function on the sub form.
Example:
Main Form Variables: EmployerNo, Received Date, Receipt No. and Amount;. Now I want to populate a temp table with these variables and run the form using the function. Below is what I think the function would look like:
TmpItem.DELETEALL;
Employee.SETRANGE("Employer No.",EmployerNo);
IF Employee.FIND('-')
THEN REPEAT
EntryNo := EntryNo + 1;
TmpItem.ReceiptNo := "Receipt No.";
TmpItem.ReceivedDate := "Received Date";
TmpItem.Amount := Amount;
TmpItem."Entry No." := EntryNo;
TmpItem."Employee No." := Employee."No.";
TmpItem."Employer No." := Employee."Employer No.";
TmpItem.INSERT();
UNTIL Employee.NEXT=0;

I've run the above function without the variables as I don't know how to get them from main form to function in subform but the form closes when the function finishes running and data is inserted to the temp table. NB I checked by using a real table instead of temp table.
Now my problems are:
1. How to pass these variables which are on the main form to the function in the subform.
2. Insert the data to temp table then run the form based on the temp table and then edit whatever I'd to edit and post the edited data to a real table called contributions.

Any ideas please!
Few years ago we were not existing and few years to come we would be in the grave! So what will benefit us in the grave?

Answers

  • AlbertvhAlbertvh Member Posts: 516
    Hi

    you could set your variables like this
    CurrForm.MySubForm.FORM.MyFunction(EmployerNo,"Received Date", "Receipt No.",Amount);
    

    Then in your subform

    MyFunction(EmployerNo: Code,ReceivedDate: Date,ReceiptNo: Code,Amount: Decimal)
    your code comes here

    Hope this gets you going

    Albert
  • zulqzulq Member Posts: 204
    Hi Albertvh,
    Try your code but it doesn't work. When I try to declare the function I got an error as the maximum length is only 30 character and when I declare the function as PopulateAut and then use
    PopulateAut(EmployerNo:Code,DateReceived:Date, FromDate:Date,ToDate:Date,ReceiptNo:Text)
    
    an error pops up saying A maximum of 0 parameters should be used when calling the function...

    Where am I get it wrong please!
    Few years ago we were not existing and few years to come we would be in the grave! So what will benefit us in the grave?
  • zulqzulq Member Posts: 204
    Hi Albertvh,
    I've solved the variable problem...Don't blame never taken a course or lecture on navision and microsfot documentation is real poor.
    Now the other questions please...To run the form edit and then post to a real table.

    Thanks.
    Few years ago we were not existing and few years to come we would be in the grave! So what will benefit us in the grave?
  • DenSterDenSter Member Posts: 8,305
    There's a document called the application designer guide, you can find it on the product CD, it's called w1w1adg.pdf or something like that. This is the best free resource you'll find. Other than that I'd suggest you take both development courses.
Sign In or Register to comment.