Solved

Search Using SQL

Posted on 2002-07-03
12
146 Views
Last Modified: 2010-05-02
How can I search and display the record in another form? Complete code..please

The user is required to key in the search value in textbox(text1) then press the cmdbutton(cmd1).The result will be displayed in form1.

I wanna do searching using ADODB.
Fieldname = Reference Number
Table = Tender
0
Comment
Question by:aidanie
  • 7
  • 4
12 Comments
 
LVL 3

Expert Comment

by:schworak
ID: 7129110
Two questions then you can have your answer...

1, Are you only returning EXACT matches to the information entered by the user or partial matches too?

Exact: bob only matches bob

Partial: red matches red, fred, redhead or anything with red in it.


2, The input is on form2 and the results are on form1? What type of output are you looking for just a list or what?
0
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7129125
Try this:

You should have "2 Forms" and a "Module" in your project, form1 and Form2
In Form1 place a textbox, command button and a ADODC1 control
In Form2 place a datagrid control(I have placed this , you can anyway place Mshflexgrid if you dont want to do any editing)

->In Form1 write the following code:

Private Sub Command1_Click()
  showDetails CInt(Text1)
  Form2.Show
End Sub

->In Form2 (No Code)

->In the Module add a procedure like this:

Public Sub showDetails(id As Integer)

 strQuery = "select * from onlinenews where id=" & id
 Form1.Adodc1.RecordSource = strQuery
 Set Form2.DataGrid1.DataSource = Form1.Adodc1

End Sub


I hope this helps!

-priya



0
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7129158
change the below code in the procedure..

>>strQuery = "select * from onlinenews where id=" & id

To..

strQuery = "select * from Tender where ReferenceNumber=" & id

Surely you must have done that, right?

-priya


0
 

Author Comment

by:aidanie
ID: 7129170
priya...i do not have ADODC control.where can i download it?
0
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7129174
For exact matches or simlar matches try putting an 2 option button next to the command button

Option1.Caption="Exact Match"
option2.Caption="Similar Matches"

Therefore the changes will be
->In Form1

Private Sub Command1_Click()
Dim MatchCreteria As String
If Option1.Value = True Then
  MatchCreteria = "E"
Else
  MatchCreteria = "L"
End If


Call showDetails((Text1.Text), MatchCreteria)
Form2.Show

End Sub


->The procedure in Module:

Public Sub showDetails(id As Variant, mC As String)

If mC = "E" Then
  strQueryMC = " where ReferenceNumber=" & id
Else
  strQueryMC = " where ReferenceNumber like '" & id & "'"
End If
StrQuery = "select * from Tender " & strQueryMC

Form1.Adodc1.RecordSource = StrQuery
Set Form2.DataGrid1.DataSource = Form1.Adodc1

End Sub

-priya
0
 
LVL 2

Accepted Solution

by:
priya_pbk earned 30 total points
ID: 7129185
You don't have to download it. It should with the VB6.

Try opening the project as "VB entereprise Edition Controls". When you choose this  as your project you will normally get all the "ActiveX controls of Microsoft". If I remember it right it is the second last control in your toolbox. Just double click it to place it on your form.

Set the 'ConnectionString' only (that is what you require at least in this application). The other things are set at runtime in our code.

I hope you know to set the connectionstring of ADODC control. Like this for your info:

Click the Adodc1 control on your form and press F4 to invoke the properties of Adodc control. Choose the connectionstring property and browse it to your database, ie ms-sql or access or whatever.

Hope this helps! (and i hope you are using VB6)

-priya

0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 2

Expert Comment

by:priya_pbk
ID: 7129223
If you have already choosen the "Standard Exe project", no problem. Go to Project menu, Click componenets,and choose "Microsoft ASO Data Control 6.0 (OLEDB)"

Any progress in this front!

-priya

0
 

Author Comment

by:aidanie
ID: 7129226
priya...i do not have ADODC control.where can i download it?
0
 

Author Comment

by:aidanie
ID: 7129256
priya...i do not have ADODC control.where can i download it?
0
 

Author Comment

by:aidanie
ID: 7129280
priya...i do not have ADODC control.where can i download it?
0
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7129299
aidanie,

Pls don't click the Refresh button of the Browser, instead, click the "ReLoad Question" at the top Right hand corner.

Did'nt you get the earlier posts, mentioning that downloading is not required, and it comes with VB6.

How far have you succeeded in implementing the above suggestions, Do let me know abt it and DON'T hit the refresh button, please!!

-priya
0
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7129439
Any Progress???

-priya
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

746 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