Find a record

Hi I am not able to find a record in a table within a form. please go throuhg the following. citycodes Global variable (RECORD - Citycodes) Primary key of citicodes tabes is cityID When the user enter pincode into the textbox- pincode , I want to display city name in the next text box. I had written the following code in the onvalidate Trigger of pincode textbox. citycodes.SETCURRENTKEY(Pincode); tmpstr := pincode; // user entered value citycodes.Pincode := tmpstr; If citycodes.FIND THEN //show value in the next control cityname := citycodes.Cityname; But this code not finding any records. But Find(’-’) and Find (’+’) are working. What wrong with this code. Thanks in advance Mathew

I have found the find(’=’) (which is the default if the direction argument is not passed) to be very problematic. I recommend sticking with (’-’) and (’+’). In the case you are stating though, you can reduce it to a 2 lines of code using the GET function. If citycodes.GET(pincode) THEN //show value in the next control cityname := citycodes.Cityname; The GET function retrieves a single record from the database based upon the primary key ONLY. Bill Benefiel Manager of Information Systems Overhead Door Company billb@ohdindy.com (317) 842-7444 ext 117

//Dont forget to blank the cityname if the record is not found // Init will clear the record if not found! If NOT citycodes.GET(pincode) THEN CityCodes.INIT; //show value in the next control cityname := citycodes.Cityname; David Cox MindSource (UK) Limited Navision Solutions Partner Email: david@mindsource.co.uk Web: www.mindsource.co.uk Edited by - David Cox on 2001 Apr 12 23:21:02

citycodes.get(pincode) 

Won’t work as pincode is not part of the primary key (which is cityID). Therefore the approach to use FIND rather than GET is the only suiteable way. However you have to cope with the fact that the number of citycodes can be zero, one or more than one. Therefore I would reccomend the following:


citycodes.SETCURRENTKEY(pincode);
citycodes.setrange(pincode,pincode);
case citycodes.count of
  0 : clear (citynames);
  1 : if citycodes.find('-') then
        cityname := citycodes.Cityname
  else begin  // let the user select
    if FORM.RUNMODAL(FORM::"citycodes",citycodes) = action::lookupok then
  cityname := citycodes.cityname;
  end;
end;

------- With best regards from Switzerland Marcus Fabian

Thanks verymuch Fabian. Since pincode is not a primary key we can’t use this in Get statement. I have tried the code written by Fabian and its working very well by using the setrange method. What I understand from this discussion is that :- To find a record always use setrange method and find(’-’) instead of using find method directly.

Well! I think that when you try to find a record by using direct assignment like below Record.somefield := some value; Record.find(****) The system initializes a new record which means that a number of fields are assigned their default values. Doing a ‘find’ after that would not always find a record because we don’t know what are the values in other fields. Compared to this, if we use ‘SETRANGE’ method, system makes sure that we are always looking at the existing records and thats why we always find the record. I hope this clears some more of the concept behind this. Regards Rubina

quote:


Originally posted by alixir: Well! I think that when you try to find a record by using direct assignment like below Record.somefield := some value; Record.find(****) The system initializes a new record which means that a number of fields are assigned their default values. Doing a ‘find’ after that would not always find a record because we don’t know what are the values in other fields. Compared to this, if we use ‘SETRANGE’ method, system makes sure that we are always looking at the existing records and thats why we always find the record. I hope this clears some more of the concept behind this. Regards Rubina


Mulitiple Key and Records SalesLine.RESET; SalesLine.SETRANGE(“Document Type”,“Document Type”); SalesLine.SETRANGE(“Document No.”,“No.”); IF SalesLine.FIND(‘-’)THEN REPEAT //// UNTIL Salesline.NEXT =0; Mulitiple Key and One Records IF SalesLine.GET(“Document Type”,“Document No.”,“Line No.”)THEN ////; Single Key IF Customer.GET(“Sell-to Customer No.”)THEN /////; David Cox MindSource (UK) Limited Navision Solutions Partner Email: david@mindsource.co.uk Web: www.mindsource.co.uk