Solved

Search Using SQL

Posted on 2002-07-03
12
147 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
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.

 
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

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

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 …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

911 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

18 Experts available now in Live!

Get 1:1 Help Now