View Single Post
 
Old 07-10-2018, 09:58 PM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 313
Default

This is my solution.

The main table is tblMemMast and tblMemRaceNo is sorted on club.

Maybe not the most efficient way but I have all the control.

Code:
procedure TfMembers.FormShow(Sender: TObject);
begin
      eRaceNo.Text:=dm.tblMemMastFieldByName('RACENO').AsString;
end;

Code:
procedure TfMembers.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
   iCnt:Integer;
begin
   CanClose:=True;
   if Trim(eRaceNo.Text) = '' then begin  // In case any spaces entered. 
      dm.tblMemMast.edit;
      dm.tblMemMastRACENO.AsString:= ''
      end
     else begin
      if (Trim(eRaceNo.Text) <> Trim(dm.tblMemMastRACENO.AsString))  and (eRaceNo.Text <> '') then begin
         with dm.tblMemRaceNo do begin
            iCnt:=0;
            First;
            while not eof do begin
               if Trim(eRaceNo.Text) = Trim(FieldByName('RACENO').AsString) then
                  iCnt:=iCnt+1;
               next;
            end;
            if iCnt = 0 then begin
               dm.tblMemMast.Edit;
               dm.tblMemMastRACENO.AsString:= eRaceNo.Text;
              end
             else begin
               CanClose:= False;
               ShowMessage('Number already exists');
               eRaceNo.Text:='';
               eRaceNo.SetFocus;
               eRaceNo.Color:=$000080FF;
             end;
         end;
      end;
   end;
end;

Last edited by Marsheng; 07-10-2018 at 10:03 PM.
Reply With Quote