Results 1 to 10 of 10
  1. #1
    Star Lounger
    Join Date
    Jun 2002
    Location
    Ontario
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Opening a second MDE through VBA

    I have the following code that worked in Access 2003. We are converting to Access 2010 and now it gives a warning message.

    Option Compare Database
    Option Explicit
    Public Declare Function ShellExecute 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
    Public Const SW_SHOWMAXIMIZED As Long = 3
    Public Const SW_SHOWNORMAL As Long = 1
    Function linkConvert()
    Dim ws_Path As String
    Dim ReturnValue, fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    ws_Path = Application.CurrentProject.Path & "\DB_Convert"
    If (fso.FileExists(ws_Path + ".mde")) Then
    ws_Path = ws_Path + ".mde"
    Else
    ws_Path = ws_Path + "_SRC.mdb"
    End If
    ReturnValue = ShellExecute(hWndAccessApp, "Open", ws_Path, 0&, 0&, SW_SHOWMAXIMIZED)
    End Function


    The warning states:

    "The command line you used to start Microsoft Access contains an option that Microsoft Access doesn't recognize. Ext and restart Microsoft Access using valid command-line options."

    If I click the okay button the DB_Convert database opens and everything proceeds as normal. Any ideas on the cause for the warning and how do I fix it

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts
    I'm not aware of any command line changes between Access 2003 and 2010, but there may well be. This Access 2007 Support article describes the options that exist for that version, and I don't believe there are any changes from 2007 to 2010.
    Wendell

  3. #3
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    This code worked OK for me in Access 2010.

    See what you get if you put in

    Debug.print ws_Path

    immediately before

    ReturnValue = ShellExecute(hWndAccessApp, "Open", ws_Path, 0&, 0&, SW_SHOWMAXIMIZED)
    Regards
    John



  4. #4
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    Another question about this: Does the message occur only when you open a specific database via the code? If so, do you get the same message if you open that database directly?

    I am wondering if the problem is something to do with the database you are trying to open, rather than with the code you have posted.
    Regards
    John



  5. #5
    Star Lounger
    Join Date
    Jun 2002
    Location
    Ontario
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The database opens fine if I open it in Windows explorer and double click. I assumed the code above effectively does the same thing. I wondered if this has anything to do with Windows 7. The code was originally run on XP.

  6. #6
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    Did you try my suggestion of putting in debug.print ws_Path?

    A forward slash is used before a command line switch. So I am wondering if it thinks you are trying to put in a command line switch.

    Your code worked for me on Windows 7 without problem.
    Regards
    John



  7. #7
    Star Lounger
    Join Date
    Jun 2002
    Location
    Ontario
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The path is correct with no extra slashes when displayed using John's suggestion

    Tom

  8. #8
    Star Lounger
    Join Date
    Jun 2002
    Location
    Ontario
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Is there an alternative way to open a second MDE using VBA?

    Tom

  9. #9
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    You could try
    Application.FollowHyperlink ws_Path
    Regards
    John



  10. #10
    Star Lounger
    Join Date
    Jun 2002
    Location
    Ontario
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks! That solved the problem.

    Tom

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •