View Single Post
  #98 (permalink)  
Old 11-23-09, 23:40
pkstormy pkstormy is offline
Moderator
 
Join Date: Dec 2004
Location: Madison, WI
Posts: 3,925
Hyperlinks and opening web pages via vba code

Example 1:
- To shell to a folder in windows explorer (not web related in this example - just shows how you can open a folder using the shell command):
Shell "C:\WINDOWS\explorer.exe """ & Me!ExportFolderName & "", vbNormalFocus

Example 2:
- To open a webpage by supplying the URLAddress
Dim objXMLHTTP, xml
Set xml = Nothing
Set xml = CreateObject("Microsoft.XMLHTTP")
xml.Open "POST", URLAddress, False
xml.send Data

Example 3:
- To pass parameters to a webpage and open it (this example opens google-map to get directions by passing the address.)

If IsNull(Me!Address1) Or IsNull(Me!City) Or IsNull(Me!State) Then
MsgBox "You must first enter the Address, City, and State!"
Exit Sub
End If
Dim dAddr As Variant
Dim Addr As Variant
Dim SAddr As Variant
Select Case Me!CenterID '<= ie. if it's Madison (case 2), return directions to the Madison location, otherwise to the Milwaukee location (case 3).
Case 2
dAddr = "1930+Monroe+St+Madison+WI+(The+Monroe+Buildin g+Su ite+200)"
Case 3
dAddr = "+848+N+12th+Milwaukee+WI+(Parking+Garage+Entr ance )"
End Select
'SAddr = Addr1 & "+" & Addr2 & "+" & City & "+" & State 'commented out - but left for example.
SAddr = Me!Address1 & "+" & Me!City & "+" & Me!State
'SAddr = Replace(Addr, " ", "+") & "+" 'commented out - but left for example.

strurl = "http://maps.google.com/maps?f=d&hl=en&geocode=&saddr=" & SAddr & "&daddr=" & dAddr & "&pw=2"

Application.FollowHyperlink strurl
__________________
Expert Database Programming
MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Last edited by pkstormy; 11-23-09 at 23:45.
Reply With Quote