none
Open a database by a link with a command row (option /cmd) RRS feed

  • Question

  • I use Access 2013 and I have a database with two type of user: 1) Boss; 2) Employer. I need to start that database with two different main form, according the type of user.

    I thought to use a link to that database with a different command row like: "C:\Program Files (x86)\Microsoft Office\Office15\MSACCESS.EXE" "C:\Users\neil\documents\masterdata.accdb" /cmd "boss" - and inside the database a module with the  Public sub like this:

    Public Sub selector()
      If Command = "boss" Then
       DoCmd.OpenForm (mBossMain)
      ElseIf Command = "employer" Then
       DoCmd.OpenForm (mEmployerMain)
      Else
       Exit Sub
      End If
    End Sub

    but this doesn't work!

    Wednesday, December 6, 2017 12:33 PM

All replies

  • Create a user table and use the network user name function to identify the user at the startup and then run what ever code you want based on the current user.

    Daniel Pineault, 2010-2017 Microsoft MVP
    Professional Support: http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net

    Wednesday, December 6, 2017 1:26 PM
  • Did you create an AutoExec macro to run your code when the database opens?

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Wednesday, December 6, 2017 1:32 PM
  • Hi Neil Wind,

    You could create an AutoExec macro to run your code to get the cmd option string from the command row.

    In the your code, you could try to refer to below code to get the whole command row and then try to pick up the option string. After that, you could try to open form according to the option string.

    CODE(In a standard module):

    Option Compare Database
    
    Public Declare Function GetCommandLine Lib "kernel32" Alias "GetCommandLineA" () As Long
    Public Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Long) As Long
    Public Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As Long) As Long
    
    Function CommandLine() As String
        Dim length As Long, pstr As Long
        pstr = GetCommandLine()
        length = lstrlen(pstr)
        CommandLine = String(length, 0)
        lstrcpy CommandLine, pstr
        arr = Split(CommandLine, "/cmd")
        cmdString = Trim(arr(UBound(arr)))
        cmdString = Mid(cmdString, 2, Len(cmdString) - 2)
        If cmdString = "boss" Then
        DoCmd.OpenForm "Form1"
        ElseIf cmdString = "employer" Then
        DoCmd.OpenForm "Form2"
        End If
    End Function

    This is AutoExec setting.

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, December 7, 2017 2:44 AM
  • Hello Neil Wind,

    Has your original issue been resolved? If it has, I would suggest you mark the helpful reply as answer or provide your solution and mark as answer to close this thread. If not, please feel free to let us know your current issue.

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 20, 2017 2:12 AM