Solved

Search Using SQL

Posted on 2002-07-03
12
149 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb6 connector to mongodb 2 140
How to set the sa password in a vb6 code for sql connection 9 62
Advice in Xamarin 21 109
Problem to line 23 74
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

749 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