Solved

Access VBA to open list of websites in the text box in their independent windows.

Posted on 2016-09-19
7
21 Views
Last Modified: 2016-09-25
I have a list of 5 to 10 websites that I want to open from access with a button. I was trying to use a list box, but I think using a textbox will be better. for example, this is how it would look...

Google.com
Bing.com
Yahoo.com
CNN.com
Apple.com
Fox.com
expert-exchange.com
____________________________

button goes here "open sites"


So basically it needs to loop through the list and open each site independently. The list will grow or shrink too.

Thank you for all the help.
0
Comment
Question by:toalexsandr
  • 3
  • 2
  • 2
7 Comments
 
LVL 34

Expert Comment

by:PatHartman
ID: 41805515
A text box won't be better.  You'd have to store the whole list as a string.  If the list varies, use a table and display it as a subform if you want to allow edits or with a listbox if you don't.

Create a loop to read a recordset, NOT the listbox or subform.  Use the FollowHyperlink method to open the sites.  That will open each site in turn in your default browser.
0
 
LVL 19
ID: 41805538
In addition to putting the sites into a tablle, you might take it one step further and use Application.FollowHyperlink  to open them to the search term you are looking for.  Each site may have differences in how it encodes a search in the URL -- search on each site and look. Be sure to include this in the table too

google uses
https://www.google.com/#q=MyWord

Bing uses
http://www.bing.com/search?q=Myword

looking for "My Phrase" on bing is
http://www.bing.com/search?q="My+Phrase"

sometimes you will see:

%20 = space
%22 = double quote mark
0
 

Author Comment

by:toalexsandr
ID: 41805798
I understand what you mean.  What about parsing a string based on either a return character or an empty space, or a comma? Can this approach be used or its not practical?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Accepted Solution

by:
toalexsandr earned 0 total points
ID: 41806687
I have figured it out. Here is the code to open sites from Access form using VBA. Unfortunately they open in separate windows, but this is good enough for me. Later I will bound it to a table field so that it will be stored in the database.
Private Sub cmdOpenURLs_Click()

   Dim strTest As String
   Dim strArray() As String
   Dim intCount As Integer
   Dim objIE As Object
    strTest = Me.txtOpenURLs
    strArray = Split(strTest, Chr(13))
For intCount = LBound(strArray) To UBound(strArray)
    Set objIE = New InternetExplorer
    objIE.Top = 0
    objIE.Left = 0
    objIE.Width = 1200
    objIE.Height = 900
    objIE.Visible = True
    objIE.Navigate ("http://" & strArray(intCount))
    Do
    DoEvents
    Loop Until objIE.ReadyState = 4
Next
    Set objIE = Nothing  
End Sub

Open in new window


URL List
I got the split function from Microsoft website and modified it a little. Split Function
0
 
LVL 19
ID: 41806845
if you want pages in the same window, you can drag Tabs once they are open
0
 
LVL 34

Expert Comment

by:PatHartman
ID: 41806912
They open in separate windows because that is what you asked them to do.

Set objIE = New InternetExplorer

The FollowHyperlink method will use an existing instance of the default browser and add tabs.
0
 

Author Closing Comment

by:toalexsandr
ID: 41814579
Works perfectly for what I needed it.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Modern/Metro styled message box and input box that directly can replace MsgBox() and InputBox()in Microsoft Access 2013 and later. Also included is a preconfigured error box to be used in error handling.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

760 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

18 Experts available now in Live!

Get 1:1 Help Now