Solved

Input box Adoquery

Posted on 2009-04-09
5
237 Views
Last Modified: 2012-05-06
I need to do a lookup of a account number. I want to use a input box.
Looking for and example to use my adoquery1 to move the dbgrid to the correct record that matches my input box values.
table:= CustomerInfo
Field:=  Account Number.
my sql.text is select * from CustomerInfo.
var

  value : string;
 

begin

  // Keep asking the user for their town

  repeat

    value := InputBox('Test program', 'Please type your town', 'Cardiff');

  until value <> '';
 

  // Show their name

  ShowMessage('Your town is '+value);

Open in new window

0
Comment
Question by:Grant Fullen
  • 2
  • 2
5 Comments
 
LVL 36

Accepted Solution

by:
Geert Gruwez earned 125 total points
Comment Utility
if AdoQuery1.Locate('TOWN', Value, [loCaseInsensitive]) then
  ShowMessage('Record located');
0
 
LVL 18

Assisted Solution

by:Johnjces
Johnjces earned 125 total points
Comment Utility
Here are a couple other suggestions:  (Spaces and single quotes are important so note them).

Also, the verb 'Like' can be '=' for an exact match..

procedure Button1Click(Sender: TObject);
begin
 ADOQuery1.Close;
 ADOQuery1.SQL.Clear;
 ADOQuery1.SQL.Add('Select * From CustomerInfo where AccountNumber Like :SrchStr');
 ADOQuery1.Parameters[0].Value := '%'+ Value + '%';
 ADOQuery1.Open;
end;

or...

procedure Button1Click(Sender: TObject);
begin
 ADOQuery1.Close;
 ADOQuery1.SQL.Clear;
 ADOQuery1.SQL.Add('Select * From CustomerInfo where AccountNumber Like '+ QuotedStr(Value));
 ADOQuery1.Open;
end;

John
0
 

Author Comment

by:Grant Fullen
Comment Utility
error
Paramater AccountNumber Has No defalt value......

procedure TForm1.ToolButton2Click(Sender: TObject);

var

  value : string;
 

begin

    value := InputBox('Invoice Number Lookup ', 'Please type your Number', '');

   ShowMessage(value);

  datamodule2.ADOQuery1.Close;

 datamodule2.ADOQuery1.SQL.Clear;

 datamodule2.ADOQuery1.SQL.Add('Select * From CustomerInfo where AccountNumber Like '+ QuotedStr(Value));

 datamodule2.ADOQuery1.Open;

Open in new window

0
 
LVL 18

Expert Comment

by:Johnjces
Comment Utility
Is the AccountNumber field spelled correctly?

Access is interpreting AccountNumber as a parameter not a fieldname which probably means that this field has a different spelling.

And last, try:

datamodule2.ADOQuery1.SQL.Add('Select * From CustomerInfo where AccountNumber Like ' + Value);

Sometimes I get confused on when a quoted string in an SQL Query is needed when piecing together strings.

John


0
 

Author Closing Comment

by:Grant Fullen
Comment Utility
Thanks
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now