Solved

Input box Adoquery

Posted on 2009-04-09
5
247 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

840 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