Check for hotel room limit per division per coordinator prior to composing document

I have the code below to check if max limit is met for hotel and division per coordinator. If limit is not met then compose doc - if met prompt with msg and do not allow to proceed. It is not working for me Please Help!

Hotel := Hotel;

choice:=@PickList( [Custom] ;@DbName ; “2007\Room Allocation” ; “Select a hotel” ; “Please select the hotel for your reservation” ;1);

TotalRooms:=@If(@IsError(@DbLookup(“” : “NoCache” ;@DbName;“SearchView”;@Name([CN];@UserName);2));0;@DbLookup(“” : “NoCache” ;@DbName;“SearchView”;@Name([CN];@UserName);2));

CurrentRooms:=@If(@IsError(@DbLookup(“” : “NoCache” ;@DbName;“SearchView”;@Name([CN];@UserName);3));0;@DbLookup(“” : “NoCache” ;@DbName;“SearchView”;@Name([CN];@UserName);3));

Division:=@If(@IsError(@DbLookup(“” : “NoCache” ;@DbName;“SearchView”;@Name([CN];@UserName);3));0;@DbLookup(“” : “NoCache” ;@DbName;“SearchView”;@Name([CN];@UserName);4));

@If(choice != “” & Division != “” & CurrentRooms>=TotalRooms;@Prompt([Ok];“Quota Exceeded or Met”;"You are unable to create any more reservations for " + choice);@Command([Compose]; @DbName ; “resv”));

@SetField(“Hotel”;“choice”)

Subject: Where do we start?

  1. You might want to look into using @IfError, since you are now using ND6.

  2. If you want to use @SetField, you should dim your field value at the top with FIELD Hotel := Hotel. You don’t really need to do that until the end, though, when you can use FIELD Hotel := choice.

  3. You are setting your variables to a numeric 0 if the lookup fails or text if your lookup is successful. @IfError would help you a lot here. Division will never = “”. It will be a numeric 0 or a string returned from the lookup.

  4. If you use @SetField, the first value is correctly a string value. But the second value should be the variable choice, not the string value “choice”. Otherwise the field Hotel will always have a value of “choice” regardless of which hotel is choisen in the picklist.

You didn’t say where your code was failing or what error you are getting, but try these suggestions and then see what else needs to be done.