Results 1 to 7 of 7
  1. #1
    Dougmeister is offline Novice
    Windows 10 Office 365
    Join Date
    Oct 2021
    Posts
    4

    Opening URLs from MS Access; force to open in new browser window?

    I know that I can use the "Shell" command to open a URL:

    Shell <Browser path and EXE> & " " & <URL>



    But it will open in a new tab if the browser already has instantiated an instance. Is there a way to force it to open in a new browser window? Perhaps with a different method, or with different parameters?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    Store the path to the file in the field, and it will open ANY file in its native application.
    Paste this code into a module,
    then its usage is: OpenNativeApp txtBox

    if the item in the text box is a URL, it will open in default explorer
    OpenNativeApp "c:\folder\file.doc"
    will open the document in word

    but it will work for all different types,
    OpenNativeApp "c:\folder"
    will open the folder explorer

    Code:
    #If Win64 Then      'Public Dclare PtrSafe Function
    Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
    Private Declare PtrSafe Function GetDesktopWindow Lib "user32" () As Long
    #else
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    #End If
    Const SW_SHOWNORMAL = 1
    Const SE_ERR_FNF = 2&
    Const SE_ERR_PNF = 3&
    Const SE_ERR_ACCESSDENIED = 5&
    Const SE_ERR_OOM = 8&
    Const SE_ERR_DLLNOTFOUND = 32&
    Const SE_ERR_SHARE = 26&
    Const SE_ERR_ASSOCINCOMPLETE = 27&
    Const SE_ERR_DDETIMEOUT = 28&
    Const SE_ERR_DDEFAIL = 29&
    Const SE_ERR_DDEBUSY = 30&
    Const SE_ERR_NOASSOC = 31&
    Const ERROR_BAD_FORMAT = 11&
    
    Public Sub OpenNativeApp(ByVal psDocName As String)
    Dim r As Long, msg As String
    r = StartDoc(psDocName)
    If r <= 32 Then
        'There was an error
        Select Case r
            Case SE_ERR_FNF
                msg = "File not found"
            Case SE_ERR_PNF
                msg = "Path not found"
            Case SE_ERR_ACCESSDENIED
                msg = "Access denied"
            Case SE_ERR_OOM
                msg = "Out of memory"
            Case SE_ERR_DLLNOTFOUND
                msg = "DLL not found"
            Case SE_ERR_SHARE
                msg = "A sharing violation occurred"
            Case SE_ERR_ASSOCINCOMPLETE
                msg = "Incomplete or invalid file association"
            Case SE_ERR_DDETIMEOUT
                msg = "DDE Time out"
            Case SE_ERR_DDEFAIL
                msg = "DDE transaction failed"
            Case SE_ERR_DDEBUSY
                msg = "DDE busy"
            Case SE_ERR_NOASSOC
                msg = "No association for file extension"
            Case ERROR_BAD_FORMAT
                msg = "Invalid EXE file or error in EXE image"
            Case Else
                msg = "Unknown error"
        End Select
    '    MsgBox msg
    End If
    End Sub

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,861
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    Dougmeister is offline Novice
    Windows 10 Office 365
    Join Date
    Oct 2021
    Posts
    4
    Right, but... what about opening it in a new window? Or am I missing that part?

    I know that I can open a URL (either via my Shell method or yours), but if the browser is already opened, then the command simply opens a new tab in the existing instance.

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    As I posted over at Mr. Excel

    https://www.excelguru.ca/content.php?184

    It's in WGM's signature but everyone seems to overlook it there.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,861
    I just responded in the newly crossposted thread made today at https://www.access-programmers.co.uk...window.319926/

    in post 3. I found a solution with one Google search that works if you use Chrome?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    It looks like Welshgasman's solution is to specificy your browser exe along with a command line argument for opening in a new window
    WGM points out that chrome's arg is
    Code:
    /new-window
    but I've also seen
    Code:
    --new-window
    Some googling it looks like firefoxes arg is
    Code:
    -new-window
    Apparently m$ edge uses the chromium engine so should be the same as chrome

    internet explorer's flag might be
    Code:
    -new
    ... just google: "<your browser> command line new window"
    Last edited by kd2017; 10-15-2021 at 10:56 AM.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 09-10-2021, 01:05 PM
  2. Replies: 4
    Last Post: 07-31-2019, 01:45 PM
  3. Replies: 4
    Last Post: 05-31-2018, 12:16 PM
  4. Replies: 3
    Last Post: 08-26-2015, 09:50 AM
  5. Replies: 3
    Last Post: 10-23-2013, 08:11 AM

Tags for this Thread

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