Solved

Input box Adoquery

Posted on 2009-04-09
5
248 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 37

Accepted Solution

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

Assisted Solution

by:Johnjces
Johnjces earned 125 total points
ID: 24116462
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
ID: 24119787
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
ID: 24119865
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
ID: 31568812
Thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

740 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