Solved

check if record exists

Posted on 2007-03-20
3
607 Views
Last Modified: 2012-06-27
I use a lookupcombo to get 'list_number' info. from a table.
I also have my contacts showing (name,surname)
in a grid (that gets data from a queery)..
So before I do anything I would like to check if a list_number allready exists
for the selected contact in the grid.
(a check would be on the exit event of the lookupcombo using a queery just for that purpose)
0
Comment
Question by:Vrtnar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 18

Expert Comment

by:Johnjces
ID: 18758858
If using ADO and an ADOTable try:

if ADOTable1.Locate('FieldName', MyLookupValue', [loCaseInsensitive]) then
 begin
 // Do something...
 end;

An ADOQuery is identical.

An SQL Query would be:

var
 MyString : String;

MyTable.Close;
MyTable.SQL.Clear;
MyTable.SQL.Add('Select SomeField where my FieldName = 'MyLookupValue'
MyTable.Open;

if MyString := MyTable.FieldByName('SomeField').AsString;
 begin

 end

Is this what you are after?

JJ

0
 

Author Comment

by:Vrtnar
ID: 18762262
No...anyway the rigt way would be this (ado) :
With ADOQuery1 do begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text := 'SELECT myfield FROM mytable WHERE myfield= ' + QuotedStr(dblookupcombo1.Text);
adoQuery1.Open;
if EOF then abort
else
ShowMessage('Value '+dblookupcombo1.Text+' allready exists!');
end;
...however I must check selected record also from the grid..
How do you search selected record in the grid?
0
 
LVL 22

Accepted Solution

by:
senad earned 125 total points
ID: 18762592
something like this :
With Query do begin //new queery
close;
Query.SQL.Clear;
if Query.FieldByName('whatever').AsString <> '' then  //this queery shows contacts
begin
SQL.Text:= 'select whatever from mytable  where whatever = ' + Query.FieldByName('wharever').AsString + ' AND whatever = ' + QuotedStr(dbLookupcombo.Text);
Query.Open;
if EOF then abort
else
ShowMessage('exists allready');
end;
end;
end;
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question