Solved

How do I open a web site for search

Posted on 2004-09-14
9
165 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…

831 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