Solved

Change from Early to Late Binding

Posted on 2007-04-03
10
563 Views
Last Modified: 2012-05-05
Could someone assist me in converting from early to late binding.  My attempts at changing the delcarations and set statements have given me a runtime error '420' ActiveX component can't create object.  This was working fine using early binding, however the situation requires a late binding solution.  I have simplified the Code somewhat to make it readable.  

Public Function GetMap(strValue As String)
'need shdocvw.dll - Microsoft Internet Controls
Dim strUrl As String
Dim shlShellWindows As Object
Dim expExplorer As Object
Set shlShellWindows = CreateObject("SHDocVw.ShellWindows")
strUrl = "www.google.com"

On Error Resume Next
'Build the url string
strUrl = strUrl & strValue
'Check and see if there are any open map windows to reuse
For Each expExplorer In shlShellWindows
  If Left(expExplorer.LocationName, 7) = "Mapping" Then
    expExplorer.Navigate strUrl
    Exit Function
  End If
Next
'Open browser window and launch map
Dim ie As Object
Set ie = CreateObject("SHDocVw.InternetExplorer")
ie.Navigate strUrl
ie.Visible = True
Set expExplorer = Nothing

End Function
0
Comment
Question by:BillPowell
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 39

Expert Comment

by:stevbe
ID: 18845351
Set shlShellWindows = CreateObject("Shell.Application")
Set ie = CreateObject("Shell.InternetExplorer")
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 18845484
CreateObject("InternetExplorer.Application")
0
 
LVL 11

Author Comment

by:BillPowell
ID: 18846127
Guys, I need to stick to the Microsoft Internet Controls dll if possible.  In code Im checking all internet explorer windows currently open to see if they are already at the site I need them to be.  If they are, I grab that window and change the LocationName.  If none of those windows are of the specified website, I open a new internet explorer window and navigate to a url.
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 12

Expert Comment

by:jkaios
ID: 18848135
Where exactly (what line) in your code does the error occurs?
0
 
LVL 11

Author Comment

by:BillPowell
ID: 18848319
This is the offending line:
Set shlShellWindows = CreateObject("SHDocVw.ShellWindows")
0
 
LVL 39

Assisted Solution

by:stevbe
stevbe earned 100 total points
ID: 18850079
EDDTK has is correctly for an individual ie window
    Set ie = CreateObject("InternetExplorer.Application")

0
 
LVL 39

Expert Comment

by:stevbe
ID: 18850185
and apparently  M$ neds to update their docs as I tried with the indo they have posted here:
http://msdn2.microsoft.com/en-us/library/aa969392.aspx
0
 
LVL 26

Assisted Solution

by:EDDYKT
EDDYKT earned 100 total points
ID: 18850257
Don't think you can call

Set shlShellWindows = CreateObject("SHDocVw.ShellWindows")

because it is hidden and must be go through the object to create.

I try this one

Set shlShellWindows = CreateObject("Shell.Application")

but has no luck

The other one should be

Set ie = CreateObject("InternetExplorer.Application")
0
 
LVL 27

Accepted Solution

by:
Ark earned 300 total points
ID: 18874755
Private Sub Command1_Click()
   Dim sha, shw
   Set sha = CreateObject("Shell.Application")
   For Each shw In sha.windows
      Debug.Print shw.LocationURL
   Next
End Sub
0
 
LVL 11

Author Comment

by:BillPowell
ID: 18875412
Ok, heres what worked finally:
Public Function GetMap(strValue As String)
Dim strUrl As String
Dim shlShellWindows As Object
Dim expExplorer As Object
Set shlShellWindows = CreateObject("Shell.Application")
strUrl = "www.google.com"

'Build the url string
strUrl = strUrl & strValue
'Check and see if there are any open map windows to reuse
For Each expExplorer In shlShellWindows.Windows
  If Left(expExplorer.LocationName, 7) = "Google" Then
    expExplorer.Navigate strUrl
    Exit Function
  End If
Next
'Open browser window and launch map
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate strUrl
ie.Visible = True
End Function

Thank for the help guys!
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

772 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