Solved

How do I open a web site for search

Posted on 2004-09-14
9
159 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
 
LVL 1

Expert Comment

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

:)
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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 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…

747 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

12 Experts available now in Live!

Get 1:1 Help Now