Count Function

Count Function

Hello,

There is form called Delivery Challan where there is a subform in which there are 2 lookup fields Design No. and  Shade No.
Now the problem i want to validate whether the particular design no or shade no exist in the stock or not and for that i believe count function is the only feasible option (if there is another do recommend).
Now i have tried the code but it seems to doesnot work with subform i guess.
Following is the code:
  1. if(Outward_Type == "Fabric")
  2. {
  3. for each  rec_Fab in Fabric
  4. {
  5. Fab_Obj = Fabric_Stock_Master[Shade_No == rec_Fab.Shade_No];
  6. if(count(rec_Fab.Design_No) == 0)   // This is the code to check whether it exists or not
  7. {
  8. alert "Does not exist";
  9. cancel submit;
  10. }
  11. else if(Fab_Obj.count() > 0)
  12. {
  13. for each  rec_Fab_Obj in Fab_Obj
  14. {
  15. if(rec_Fab_Obj.Design_No == rec_Fab.Design_No)
  16. {
  17. if(rec_Fab.Quantity > rec_Fab_Obj.Meter)
  18. {
  19. alert "Test";
  20. cancel submit;
  21. }
  22. }
  23. }
  24. }
  25. }
  26. }

But when i update the code and leave the code changes.
  1. if(Outward_Type == "Fabric")
  2. {
  3. for each  rec_Fab in Fabric
  4. {
  5. Fab_Obj = Fabric_Stock_Master[Shade_No == rec_Fab.Shade_No];
  6. if(rec_Fab.count() == 0) // This is the change in the code after i update and leave
  7. {
  8. alert "Does not exist";
  9. cancel submit;
  10. }
  11. else if(Fab_Obj.count() > 0)
  12. {
  13. for each  rec_Fab_Obj in Fab_Obj
  14. {
  15. if(rec_Fab_Obj.Design_No == rec_Fab.Design_No)
  16. {
  17. if(rec_Fab.Quantity > rec_Fab_Obj.Meter)
  18. {
  19. alert "Test";
  20. cancel submit;
  21. }
  22. }
  23. }
  24. }
  25. }
  26. }