Results 1 to 7 of 7
  1. #1
    sandman is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Oct 2021
    Location
    Tasmania
    Posts
    14

    Adding a STRING result to open an Access file in a SHELL exe Command

    I have a Form button on an access DB, that when selected opens another Access Database using the Shell command.

    This line of code works fine :

    Shell ("C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.exe J:\AccessDatabase\mydatabase.accdb"),vbNormalFocus


    Problem with the above its fixed and cannot change!



    I want to substitute the file path as a string based on a query result. so basically "strPath" is the result of that Query

    Dim strPath As String

    strPath = J:\AccessDatabase\mydatabase.accdb (result of the Query)

    Shell ("C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.exe """"" """ & strPath & """"), vbNormalFocus

    it returns File not found


    I can also get this to work using this:

    'Shell "cmd.exe /c start """" """ & strPath & """", vbNormalFocus


    Problem with this line is there are too many flashing screens.



    Ive also tried several variations on this line and get the same problem Can anyone spot the error ?


    Shell ("C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.exe """"" """ & strPath & """"), vbNormalFocus

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    What do you mean by "result of the query"? How are you obtaining value for strPath?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    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
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Put your entire path in a variable then debug.print the variable to the immediate window. You should be able to spot what is wrong with your path. It might only be a missing slash, or you have spaces that need to be wrapped in quotes. That's troubleshooting 101.

    When you don't put code/sql in code tags (# on forum posting toolbar) it's very hard to distinguish a whole whack of quotes like that. Plus, the forum will interject spaces after about 50 contiguous characters, then everyone is questioning spaces that don't seem to belong in what you posted.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    sandman is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Oct 2021
    Location
    Tasmania
    Posts
    14
    June7
    Im using Dlookup to get the result from the query.

    Micron
    Ive run it in the immediate window, all it returns is C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.exe
    it completely misses anything after .exe

  6. #6
    sandman is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Oct 2021
    Location
    Tasmania
    Posts
    14
    Thanks for all the input.
    Suggestion from Micron was key.

    I fiinally got it to run using this:

    Dim strPath as string
    strPath = 'using a dlookup for specific query results

    Shell ("C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.exe" & " " & strPath & ""), vbNormalFocus

  7. #7
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I've played with it using shell but I get a strange error re 'a switch Access doesn't recognize'. It's getting late so I must quit for now but am thinking of creating a shortcut to see if it accepts the same syntax. However, there are other ways to open an Access db that don't involve Shell. Perhaps that would be better? Your situation might be due to spaces in file path. Whenever I create files/folders I never use spaces.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Can not open PDF file via Shell
    By Etoimos in forum Forms
    Replies: 2
    Last Post: 10-02-2020, 09:54 AM
  2. Replies: 8
    Last Post: 02-05-2013, 02:36 PM
  3. Replies: 6
    Last Post: 09-14-2012, 11:58 AM
  4. Replies: 7
    Last Post: 06-18-2012, 11:31 AM
  5. Open (shell) a program and pass a file
    By Olszanski in forum Programming
    Replies: 2
    Last Post: 07-27-2010, 03:52 PM

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