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
Solved

How do I open a web site for search

Posted on 2004-09-14
9
166 Views
Last Modified: 2010-05-02
Hi everyone.

What I am trying to do is this: I am not sure whether I can do it or not...But, you guys tell me how much I do.....

In my form there a text box and button;
Text box contains the string search for the web search (yahoo.com)
so, when the user click the button, I would like to open up yahoo.com and search for that string (txt.1text)
 ***** Then, I would like to open up the first search item...?(Is it possible?)


 Can I able to do it? can anyone tell me how to do it?

Thank you ...alll
0
Comment
Question by:neonlights
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 5

Expert Comment

by:KarcOrigin
ID: 12060615
You can use MS Internet explorer library (Add: Project/Reference)

Private Sub ShowMe()
    With IE
        .Navigate "http://www.yahoo.com"
        Do While .Busy
            DoEvents
        Loop
        .Document.All.txtYahooSearch.Value = Me.txtSearch.Text
        .Visible = True
        .Document.Test.Submit
    End With
End Sub

In the above example I have assumed that Yahoo search page contains txtYahooSearch textbox, and the search form name is Test. You can set the .Visible property to False in case you want to do everything in the background. Do not forget to close and release the IE object when everything is finished. Below is the code to quit and release the IE object.

Private Sub CloseMe()
    With IE
        .Quit
        DoEvents
    End With
    Unload Me
End Sub

Cheers!

Good luck.
0
 
LVL 1

Expert Comment

by:martin_watts
ID: 12063152
If you are willing to use Google instead of Yahoo, you can benefit of their "I'm feeling lucky" feature, which will make implementation very simple:

Shell "http://www.google.com/search?hl=en&ie=UTF-8&q=" & Replace(Me.txtSearch.Text, " ", "+") & "&btnI=Google+Search"

The replace is used to convert the spaces in your search string to "+", so the url remains valid. This is not sufficient for correct URL formatting, so if you are planning on running more complex queries, you'll have to convert all odd characters to their hexedecimal equivalent (e.g. "%3F" instead of "/").
0
 
LVL 1

Expert Comment

by:sarulprakash
ID: 12065229
Hi neon,
The searching part in yahoo is simple.

The text in your text box replace every whitespace by "+" symbol.
ex: if the search text is "how to create a form"
the modified query looks like "how+to+create+a+form"
then execute this statement:

shell("c:\program files\Internet Explorer\iexplore.exe http://search.yahoo.com/search?p=" & searchTxt)

This opens the search result page in the Internet Explorer window.

Cheers,
Arul...
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 1

Expert Comment

by:sarulprakash
ID: 12065236
where searchTxt is the modified query.

:)
0
 
LVL 14

Accepted Solution

by:
aelatik earned 500 total points
ID: 12067764
You can query yahoo for a searchstring and open any desired link on that page, check this out :

Private Sub Command1_Click()
    Call SearchAndOpen("http://search.yahoo.com", Text1.Text, 1) ' If you change "1" to "2" for example it would open the second link.
End Sub

Function SearchAndOpen(URL As String, SearchString As String, Item As Long)
    Dim LINKS As New Collection
    Dim IE As Object
    Set IE = CreateObject("internetexplorer.application")
        IE.Visible = True
        IE.navigate URL & "/search?p=" & SearchString
        While IE.busy: DoEvents: Wend
        For i = 0 To IE.Document.All.length - 1
            If UCase(IE.Document.All(i).Tagname) = "A" Then
                If IE.Document.All(i).Classname = "yschttl" Then
                    LINKS.Add IE.Document.All(i).href
                    ' // Show the name of the link
                    ' Debug.Print IE.Document.All(i).innertext
                    ' // Show the link
                    ' Debug.Print IE.Document.All(i).href
                End If
            End If
        Next
        'MsgBox "Found " & LINKS.Count & " Results for searchstring '" & SearchString & "'"
        If Item > 0 And Item <= LINKS.Count Then
            IE.navigate LINKS(Item)
            While IE.busy: DoEvents: Wend
        End If
End Function

Good luck,
Ayhan Elatik
0
 

Author Comment

by:neonlights
ID: 12120465
Hi Ayhan Elatik, when I do your search function, I am getting the first item, but getting error message: "You don't have permission to ......

I tried many times....Do you know why?

Thanks a lot
0
 
LVL 14

Expert Comment

by:aelatik
ID: 12123225
Thats weird, it works with me. I also tested it on other computers and it worked there too.

What version of IE are you using ? Maybe that is conflicting or something...
0
 

Author Comment

by:neonlights
ID: 12124466
Hi, thanks for your response, I would like to find a solution that works on every pc - regardless of the IE, am I right?

Everytime, I did it, getting the same error message.......

But, my IS is 6, windows xp.
0
 

Author Comment

by:neonlights
ID: 12152084
It is working....sorry...my mistake aelatik


Cheers!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Title # Comments Views Activity
VB 6.0 printer how to align 6 66
SSRS expression Issue finding a string 10 89
How to make an ADE file by code? 11 94
clicking a shape in a frame array vb6 3 46
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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.
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…
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…

808 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