?
Solved

How do I open a web site for search

Posted on 2004-09-14
9
Medium Priority
?
177 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
[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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Expert Comment

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

:)
0
 
LVL 14

Accepted Solution

by:
aelatik earned 2000 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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…
Suggested Courses
Course of the Month10 days, 8 hours left to enroll

765 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