Solved

Input box Adoquery

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
A short film showing how OnPage and Connectwise integration works.

932 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