Open Web browser with code

  • Thread starter Thread starter Lisa B.
  • Start date Start date
L

Lisa B.

Does anyone know the code to open the web browser and go to a URL listed in
a field.

I know I can do it if I make the field a hyperlink, but the field is on a
sub form and will be invisible to the user.
 
Lisa,

Using the Microsoft Web Browser object, in the click event of a button, the
following works:


Dim ctl As Object
Dim var As Long

Set ctl = Me.ctlWebBrowser.Object

ctl.Navigate ("www.google.com")


While you're at it, you can test for and use the Updated event and run code
if required:

Private Sub ctlWebBrowser_Updated(Code As Integer)
Me.Command1.Visible = True
Me.Command1.SetFocus
End Sub

Use the Object Browser to inspect all the events and properties.

Steve
 
Occurs to me I may have missed your question. I was thinking of the browser
object inserted on a form...

In code this works to start IE and go to 'www.msn.com':

Shell "C:\Program Files\Internet Explorer\iexplore.exe www.msn.com"

Steve
 
Shell "C:\Program Files\Internet Explorer\iexplore.exe www.msn.com"

Curious -- putting a well formed URI into the Start Programs/ Run box like
this works as expected:-

http://www.helios.com

but using the same thing as a shell command results in a file not found
error.

? shell( "http://www.helios.com" )

So what is the correct procedure for calling the _default_ browser without
having to hard-code the path and executable?

Tim F
 
OK, that works. However when IE opens it is minimized to the startbar. Is
there a way to have it open as the active window?

Now, I have this code behind a button
----------------------------------------------------------------
Dim URLAddress As String

GL_Address =
Forms![frmRecruitment]![frmAppointment].Form![frmAppointmentLocation].Form![
Address]
GL_City =
Forms![frmRecruitment]![frmAppointment].Form![frmAppointmentLocation].Form![
City]
GL_State = Me![frmAppointmentLocation].Form![StateID]
GL_Zip = Me![frmAppointmentLocation].Form![Zip]

MapAddress = ChangeStr(GL_Address, Chr$(32), Chr$(43), 0)
MapCity = ChangeStr(GL_City, Chr$(32), Chr$(43), 0)

URLAddress =
"http://www.mapquest.com/maps/map.adp?country=US&addtohistory=&address=" +
MapAddress + "state=" + GL_State + "&zipcode=" + GL_Zip +
"&homesubmit=Get+Map"

Shell "C:\Program Files\Internet Explorer\iexplore.exe " & URLAddress
--------------------------------------------------------------------------

This opens IE to mapquest and finds an address
 
Try:

Shell "C:\Program Files\Internet Explorer\iexplore.exe " & URLAddress
,vbMaximizedFocus



Lisa B. said:
OK, that works. However when IE opens it is minimized to the startbar. Is
there a way to have it open as the active window?

Now, I have this code behind a button
----------------------------------------------------------------
Dim URLAddress As String

GL_Address =
Forms![frmRecruitment]![frmAppointment].Form![frmAppointmentLocation].Form![
Address]
GL_City =
Forms![frmRecruitment]![frmAppointment].Form![frmAppointmentLocation].Form![
City]
GL_State = Me![frmAppointmentLocation].Form![StateID]
GL_Zip = Me![frmAppointmentLocation].Form![Zip]

MapAddress = ChangeStr(GL_Address, Chr$(32), Chr$(43), 0)
MapCity = ChangeStr(GL_City, Chr$(32), Chr$(43), 0)

URLAddress =
"http://www.mapquest.com/maps/map.adp?country=US&addtohistory=&address=" +
MapAddress + "state=" + GL_State + "&zipcode=" + GL_Zip +
"&homesubmit=Get+Map"

Shell "C:\Program Files\Internet Explorer\iexplore.exe " & URLAddress
--------------------------------------------------------------------------

This opens IE to mapquest and finds an address






Occurs to me I may have missed your question. I was thinking of the browser
object inserted on a form...

In code this works to start IE and go to 'www.msn.com':

Shell "C:\Program Files\Internet Explorer\iexplore.exe www.msn.com"

Steve

<SteveT> wrote in message news:%[email protected]... button,
the on
 
This works, Thank You.

Try:

Shell "C:\Program Files\Internet Explorer\iexplore.exe " & URLAddress
,vbMaximizedFocus



Lisa B. said:
OK, that works. However when IE opens it is minimized to the startbar. Is
there a way to have it open as the active window?

Now, I have this code behind a button
----------------------------------------------------------------
Dim URLAddress As String

GL_Address =
Forms![frmRecruitment]![frmAppointment].Form![frmAppointmentLocation].Form![
Address]
GL_City =
Forms![frmRecruitment]![frmAppointment].Form![frmAppointmentLocation].Form![
City]
GL_State = Me![frmAppointmentLocation].Form![StateID]
GL_Zip = Me![frmAppointmentLocation].Form![Zip]

MapAddress = ChangeStr(GL_Address, Chr$(32), Chr$(43), 0)
MapCity = ChangeStr(GL_City, Chr$(32), Chr$(43), 0)

URLAddress =
"http://www.mapquest.com/maps/map.adp?country=US&addtohistory=&address=" +
MapAddress + "state=" + GL_State + "&zipcode=" + GL_Zip +
"&homesubmit=Get+Map"

Shell "C:\Program Files\Internet Explorer\iexplore.exe " & URLAddress
--------------------------------------------------------------------------

This opens IE to mapquest and finds an address






Occurs to me I may have missed your question. I was thinking of the browser
object inserted on a form...

In code this works to start IE and go to 'www.msn.com':

Shell "C:\Program Files\Internet Explorer\iexplore.exe www.msn.com"

Steve

<SteveT> wrote in message Lisa,

Using the Microsoft Web Browser object, in the click event of a button,
the
following works:


Dim ctl As Object
Dim var As Long

Set ctl = Me.ctlWebBrowser.Object

ctl.Navigate ("www.google.com")


While you're at it, you can test for and use the Updated event and run
code
if required:

Private Sub ctlWebBrowser_Updated(Code As Integer)
Me.Command1.Visible = True
Me.Command1.SetFocus
End Sub

Use the Object Browser to inspect all the events and properties.

Steve



Does anyone know the code to open the web browser and go to a URL listed
in
a field.

I know I can do it if I make the field a hyperlink, but the field
is
on
a
sub form and will be invisible to the user.
 
Back
Top