Bosanac
asked on
Check if record exists
I am entering new record directly into the ADOTable1 (in the grid)
using dbnavigator for inserting/posting/editing etc..
How can I have a message displayed if I enter a record that is allready in the database
as soon as I try move to move to the next field ?
using dbnavigator for inserting/posting/editing etc..
How can I have a message displayed if I enter a record that is allready in the database
as soon as I try move to move to the next field ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Use within your datasource the event OnUpdateData
if YourField = '' then
begin
MessageDLG('Field value needs some input here....', mtWarning, [mbOK], 0);
with YourEditField do begin Show; SetFocus; end;
Abort;
end;
etc....
if YourField = '' then
begin
MessageDLG('Field value needs some input here....', mtWarning, [mbOK], 0);
with YourEditField do begin Show; SetFocus; end;
Abort;
end;
etc....
Use the OnBeforePost event in your ADOTable, IE.
procedure TForm1.MyADOTable1BeforePo st(DataSet : TDataSet);
begin
if MyADOTable.Locate('MyField Name', TextToFindInMyFieldName, [loCaseInsensitive] then
begin
{Do what you need to do...}
end;
end;
procedure TForm1.MyADOTable1BeforePo
begin
if MyADOTable.Locate('MyField
begin
{Do what you need to do...}
end;
end;
ASKER
whats 'TextToFindInMyFieldName' ?
If you are trying to find "Smith" in your field name 'LastName' then "Smith" would be the TextToFindInMyFieldName, which in the example is LastName.
This way you will find a record if it exists whose last name is Smith.
This way you will find a record if it exists whose last name is Smith.
ASKER
I am entering data into the grid directly and I do not know what record to search but to check the one I am entering (so I do not enter a duplicate record by any chance).
Is there a way..or perhaps before post or something ?
Is there a way..or perhaps before post or something ?
Place your validation before post on the OnUpdateData event on your datasource.
if YourCheckHere then
begin
MessageDLG('This is not what you want...', mtWarning, [mbOK], 0);
with YourEditField do begin Show; SetFocus; end;
Abort;
end;
etc, continue your check's here...
if YourCheckHere then
begin
MessageDLG('This is not what you want...', mtWarning, [mbOK], 0);
with YourEditField do begin Show; SetFocus; end;
Abort;
end;
etc, continue your check's here...
Forced accept.
Computer101
EE Admin
Computer101
EE Admin
ASKER
how is that supposed to look like