Page 2 of 2 FirstFirst 12
Results 16 to 24 of 24
  1. #16
    Sense is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Nov 2018
    Posts
    15
    I have tried the first code 'stand alone', So without any of my code in it. I adjusted it to internetexplorer.application and added a visible=true line to check if it created a new instance.

    Code:
     Function MyFunctionName()
    On Error GoTo Err_Handler
    '...other unrelated code here if needed
      'Start IE
        On Error Resume Next
        Dim oIE As Object
        Set oIE = GetObject(, "InternetExporer.Application")    'Bind to existing instance of Internet Explorer
     
        If Err.Number <> 0 Then    'Could not get instance of Internet Explorer, so create a new one
            Err.Clear
            On Error GoTo Err_Handler
            Set oIE = CreateObject("InternetExplorer.Application")
            bIEOpened = False
        Else    'IE was already running
            bIEOpened = True
        End If
        
        On Error GoTo Err_Handler
    oIE.Visible = True
    '...more unrelated code here
      Set oIE = Nothing
    Exit_Handler: Exit Function
    Err_Handler: MsgBox "Error " & Err.Number & " in MyFunctionName routine: " & Err.Description
    Resume Exit_Handler
    End Function
    1. Running with internet explorer closed



    runs getobject can't find object
    checks err.number
    Creates object
    has made a new ie object

    2. Running with internet explorer opened

    runs getobject can't find object
    checks err.number
    Creates object
    has made a new ie object

    So apparently it can make a new instance but cannot find an open one.

  2. #17
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    It seems that, unlike applications such as Word, Outlook etc, IE ALWAYS opens a new instance

    Slightly shorter version of same code

    Code:
     Function MyFunctionName()On Error GoTo Err_Handler
    
    
    '...other unrelated code here if needed
      'Start IE
        On Error Resume Next
        Dim oIE As Object
        Set oIE = GetObject(, "InternetExporer.Application")    'Bind to existing instance of Internet Explorer
    '    Debug.Print Err.Number & " " & Err.Description
        If Err.Number = 429 Then   'Could not get instance of Internet Explorer, so create a new one
            Err.Clear
            On Error GoTo Err_Handler
            Set oIE = CreateObject("InternetExplorer.Application")
        End If
        
        bIEOpened = True
        
        On Error GoTo Err_Handler
        
        oIE.Visible = True
        
    '...more unrelated code here
    
    
      Set oIE = Nothing
      
    Exit_Handler:
        Exit Function
        
    Err_Handler:
      '  If Err = 429 Then Resume Next
        MsgBox "Error " & Err.Number & " in MyFunctionName routine: " & Err.Description
        Resume Exit_Handler
    End Function
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  3. #18
    Sense is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Nov 2018
    Posts
    15
    Quote Originally Posted by ridders52 View Post
    It seems that, unlike applications such as Word, Outlook etc, IE ALWAYS opens a new instance

    Perhaps.. the funny thing is that in excel my original code works without a problem... I don't get it

  4. #19
    Sense is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Nov 2018
    Posts
    15
    Quote Originally Posted by June7 View Post
    A function is required if need to return a value to calling procedure. Also, queries and Access controls can see functions but not subs.
    Okay thanks! So it's better to use functions. Is there any reason why I should use subs instead of Functions?

  5. #20
    Sense is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Nov 2018
    Posts
    15
    Okay I understand now that shell.application is able to find an open browser even though it's in fact the windows explorer. InternetExplorer.application is unable to do that.
    So I would say have to get the shell.application object working in access.

  6. #21
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Quote Originally Posted by Sense View Post
    Okay thanks! So it's better to use functions. Is there any reason why I should use subs instead of Functions?
    Some developers only use functions even where a sub will work - the idea being it gives maximum flexibility
    Other developers of course think that is totally inappropriate.

    The code below allows you to easily use the Shell command in Access
    Place the code in a standard module

    Code:
    Option Compare Database
    Option Explicit
    
    'API declarations for 32-bit/64-bit Access
    '###############################################
    #If VBA7 Then 'use PtrSafe & LongPtr
        Private Declare PtrSafe Function apiShellExecute Lib "shell32.dll" _
            Alias "ShellExecuteA" _
            (ByVal hWnd As LongPtr, _
            ByVal lpOperation As String, _
            ByVal lpFile As String, _
            ByVal lpParameters As String, _
            ByVal lpDirectory As String, _
            ByVal nShowCmd As Long) _
            As Long
    #Else '32-bit Office
        Private Declare Function apiShellExecute Lib "shell32.dll" _
            Alias "ShellExecuteA" _
            (ByVal hWnd As Long, _
            ByVal lpOperation As String, _
            ByVal lpFile As String, _
            ByVal lpParameters As String, _
            ByVal lpDirectory As String, _
            ByVal nShowCmd As Long) _
            As Long
    #End If
    '###############################################
    
    Public Sub ShellEx(ByVal Path As String, Optional ByVal Parameters As String, Optional ByVal HideWindow As Boolean)
    
        If Dir(Path) > "" Then
            apiShellExecute 0, "open", Path, Parameters, "", IIf(HideWindow, 0, 1)
        Else
            MsgBox "Can't find program"
        End If
    
    End Sub
    Here are 3 examples of it in use that you can try
    Code:
    Public Function OpenMagnifier()
        ShellEx "c:\windows\system32\magnify.exe", , 0
    End Function
    
    
    Public Function RunOSK()
    'opens on screen keyboard 
        apiShellExecute 0, vbNullString, "osk.exe", vbNullString, "C:\", 1
       ' ShellEx "c:\windows\system32\osk.exe", , True
    End Function
    
    
    Public Function OpenTabTip()
    'opens tablet screen keyboard 
       ShellEx "C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe", , True
    End Function
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  7. #22
    Sense is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Nov 2018
    Posts
    15
    After some more research I conclude my code and yours ofcourse should work. The problem may have to do with the version of access, company restriction or anything environmental.
    Now ranman256 had this idea of using a internetbrowser control in a form. I tried that and it works so I'll use it for this case.

    I will take a look at the Shell code soon.


    Thanks all for your help!

  8. #23
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Strange. Can't see a post from Ranman in this thread so forgive the follow up question
    There are two types of web browser control in Access

    The first is on the design toolbar and is fairly simple in terms of what it can do. Basically opens a web page externally
    Then there is the ActiveX version which is much more powerful, allowing you to open almost any external document (PDF/DOCX/XLSX etc) as well as web pages in a browser window within Access.

    If the former, how is it better than what you had?
    If the latter, do note that some organisations and individuals do not allow the use of ActiveX controls due to potentials risks with rogue controls
    Last edited by isladogs; 11-21-2018 at 05:49 PM.
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  9. #24
    Sense is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Nov 2018
    Posts
    15
    Ahhh you're right it didn't solve anything.. Tomorrow I'll check your shell code

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 11-16-2018, 10:47 AM
  2. Trying to control Internet Explorer in VBA
    By Glenn_Suggs in forum Modules
    Replies: 21
    Last Post: 09-25-2014, 08:44 AM
  3. VBA Internet Explorer Print Specific Page
    By luckasx in forum Access
    Replies: 10
    Last Post: 12-03-2013, 09:10 AM
  4. Find Internet Explorer window based on specific site
    By redbull in forum Code Repository
    Replies: 0
    Last Post: 04-02-2013, 09:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums