[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How do I open a web site for search

Posted on 2004-09-14
9
Medium Priority
?
180 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
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!

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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 …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

656 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