Results 1 to 3 of 3
  1. #1
    djblois is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Nov 2018
    Posts
    6

    Passing Arguments to Forms using OpenArgs


    I have been working on passing multiple arguments between forms using the OpenArgs property. I wanted to great a method so that I can pass as many as I want and not have to recreate the wheel each time. This is the Function I came up with:

    Code:
    Public Function GetFormArgument(allArguments As String, argumentName As String) As Variant
    
        Dim StartOfArgumentName As Integer: StartOfArgumentName = InStr(1, allArguments, argumentName)
        Dim StartOfVariable As Integer: StartOfVariable = InStr(StartOfArgumentName, allArguments, ":") + 1
        Dim EndOfVariable As Integer: EndOfVariable = IIf(InStr(StartOfVariable, allArguments, "|") = 0, Len(allArguments), InStr(StartOfVariable, allArguments, "|") - 1)
        Dim LengthOfVariable As Integer: LengthOfVariable = EndOfVariable - StartOfVariable + 1
        GetFormArgument = Mid(allArguments, StartOfVariable, LengthOfVariable)
    
    
    End Function
    On the open form method do this:

    Code:
    Call DoCmd.OpenForm(FormName:="frm1", DataMode:=acFormEdit, WindowMode:=acDialog, OpenArgs:="Argument1:True|Argument2:Name")
    Then to Parse the Argument you need:

    Code:
    Argument2 = GetFormArgument(Me.OpenArgs, "Argument2")
    This code works perfectly fine. I am just posting it here for 2 reasons.

    1) The function looks a little complicated, if anyone has any ideas to reduce it a little.
    2) Even if no one has any ideas, this may be useful for someone else who wants to be able to do this.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    just use a screen object (txtBox,etc)
    or
    a global variable
    or
    a form modular variable

    no confusion on openargs

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I apologize in advance for not being a fan of that; don't want to discourage anyone from contributing or asking for help.

    Or pass a comma delimited set of values. Open form. If you know what you want to pass as arguments you can just as easily refer to what was passed and deal with it in the opening form (because you know what needed to be passed) rather than doing that in the code that opens it. I'm not sure I see the need to complicate it like that but maybe I'm missing something.
    not have to recreate the wheel each time
    I advocate that all the time. It's just that in this case it seems to me that having to code to pass needed argument types and values each time doesn't really prevent that.
    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. Replies: 33
    Last Post: 09-22-2020, 04:37 PM
  2. Passing Multiple Arguments between Forms
    By shylock in forum Access
    Replies: 5
    Last Post: 03-06-2019, 01:22 PM
  3. Passing arguments to a public sub
    By EonsTimE in forum Programming
    Replies: 4
    Last Post: 04-05-2016, 03:29 PM
  4. VBA passing Array arguments to procedure
    By George in forum Access
    Replies: 2
    Last Post: 05-13-2015, 10:03 AM
  5. VBA ByVal vs ByRef Passing Arguments
    By ylatodd in forum Programming
    Replies: 5
    Last Post: 10-22-2013, 02:49 PM

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