locked
How to load OpenArgs into an Array RRS feed

  • Question

  • Several of my forms call a Popup form (DoCmd.OpenForm) and they pass in a string containing one or more comma delimited variables.  Presently I am parsing the string into other variables.  What would provide more flexibility would be to load me.OpenArgs into an array, then the form logic can simple check the existence of an element.

    I have had not luck in finding help on how take the string passed into Args (e.g. "Customer, Path, FileType, Destination") and load it into an array.  I am not a fan of Global Variables so any help would be Greatly Appreciated!

    Thank you in advance!

    Brian S

    Friday, July 15, 2016 1:00 AM

Answers

  • Hi Brian. The following code snippet will parse and load the OpenArgs string into a String Array.

    Dim strArgs() As String
    
    If Not IsNull(Me.OpenArgs) Then
        strArgs = Split(Me.OpenArgs, ",")
    End If
    
    

    Hope it helps...

    • Marked as answer by BrianSir Friday, July 15, 2016 4:07 PM
    Friday, July 15, 2016 2:05 AM

All replies

  • Hi Brian. The following code snippet will parse and load the OpenArgs string into a String Array.

    Dim strArgs() As String
    
    If Not IsNull(Me.OpenArgs) Then
        strArgs = Split(Me.OpenArgs, ",")
    End If
    
    

    Hope it helps...

    • Marked as answer by BrianSir Friday, July 15, 2016 4:07 PM
    Friday, July 15, 2016 2:05 AM
  • Thanks this is perfect.
    Friday, July 15, 2016 4:08 PM
  • You might also like to take a look at Args.zip in my public databases folder at:

    https://onedrive.live.com/?cid=44CC60D7FEA42912&id=44CC60D7FEA42912!169

    Note that if you are using an earlier version of Access you might find that the colour of some form objects such as buttons shows incorrectly and you will need to amend the form design accordingly.  

    If you have difficulty opening the link copy its text (NB, not the link location) and paste it into your browser's address bar.

    This little demo file illustrates the use of a module originally developed by Stuart McCall for passing multiple arguments as a tokenised string, and later extended by myself to allow the passing of named arguments.

    Ken Sheridan, Stafford, England

    Friday, July 15, 2016 4:33 PM
  • Thanks this is perfect.

    Hi Brian. You're welcome. Glad we could assist. Good luck with your project.
    Friday, July 15, 2016 4:35 PM
  • So what if your Openargs value is "1,23,456,7890"?

    You would have to Very Carefully document that this is an OrderStatus, CustomerID, SalesrepID, etc. You get my drift.

    That's why I use "name/value pairs" like you see in a querystring in the browser:
    "OrderStatusID=1&CustomerID=23&SalesrepID=456..."
    This makes OpenArgs self-describing, a big advantage.

    Then I call a function to split these items and put them in a Scripting.Dictionary object. Then I can write:
    Me.OrderStatusID = dict("OrderStatusID")

    and also:
    if dict.Exists("SalesrepID") then ...

    If a value can have an embedded separator like & or =, then I use UuEncode, just like on the web.

    This approach also makes OpenArgs independent of the order (and even existence) of the individual elements.


    -Tom. Microsoft Access MVP

    Friday, July 15, 2016 4:57 PM