Hi! I Pasted your code in my Lazarus' Text Editor.... I think the error is in the Query. Try with: SQLQuery1.SQL.Text:='SELECT enquiryreferencenumber FROM registration WHERE fname=' + #39 + fname.Text+ #39 + ' AND sname=' + #39 +sname.Text+ #39 + ' ORDER BY enquiryreferencenumber DESC LIMIT 1;'; On 28 May 2008 at 14:31, Dave Coventry wrote: