Results 1 to 8 of 8
  1. #1
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496

    dynamically define a nariable name

    Not that often, but often enough, i pass several variables to a form through open arguments.
    And thought i could streamline the retrieval of them through a simple snippet of reusable code.

    (I "think" the answer is you can't do what i'm trying to do... but....)
    the problem is defining a variable for each argument (sometimes there is only 1; other times, there may be several (maybe 3 or 4 or 5)
    the arguments then get assigned to controls on the form..

    here's the code:


    Code:
    Private Sub Form_Load()
    
        If Len(Me.OpenArgs) > 0 Then
            strOpenArgs = Me.OpenArgs
            intVarCnt = 1
            Do While InStr(strOpenArgs, "|") <> 0
                strVar = srtVar & intVarCnt
                intPos = InStr(strOpenArgs, "|")
                strVar = Left(Me.OpenArgs, intPos - 1)
                strOpenArgs = Mid(strOpenArgs, intPos + 1)
                intVarCnt = intVarCnt + 1
            Loop
            ' and then pickup the last argument (after the last pipe)
            strVar = "var" & intVarCnt
            intPos = InStr(strOpenArgs, "|")
            strVar = Left(Me.OpenArgs, intPos - 1)
            strOpenArgs = Mid(strOpenArgs, intPos + 1)
        End If
        
    End Sub
    as always, with appreciation in advance,
    thnx,
    m.

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    You don't make use of Option Explicit do you? That would be an oversight, I'd say.

    I don't see why you can't string together a bunch of parameters for OpenArgs, but not in the load event of the form. There wouldn't be much point as the property is usually set from DoCmd in another form, not in the form you're opening. Makes no sense to me to do it in the opened form and use the parameters after that - might as well pull them in from the second form (from the first?).
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    That code appears to be in the form being opened. I don't think you can do what you're trying to do, but simpler would be to use the Split() function on OpenArgs. That will put however many items were passed into an array, and you can refer to any member of that array easily, or loop it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    Yea…
    I kinda noted the option explicit problem
    And thought I’d duck it for now (knowing fully it might kill the whole approach)

    I do send the arguments with the DoCmd open form…. This is about retrieving them in the new form
    The arguments received might be:
    textA|textB|textC and I was hoping to break it into textA. textB. textC with generic code for an undetermined number of items

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Just making sure you noticed post 3.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    got it
    thnks
    ....that makes sense

    (BTW split().... new language for me; and pretty slick if you ask me. such an obvious code to have !)
    Last edited by markjkubicki; 04-04-2022 at 07:25 PM. Reason: (hit send too soon)

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem, post back if you get stuck implementing it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    And thought I’d duck it for now (knowing fully it might kill the whole approach)
    You're just asking for trouble.
    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. Automated email define who it's sent from
    By Robyn_P in forum Programming
    Replies: 4
    Last Post: 01-18-2019, 05:47 AM
  2. Cannot define field more than once
    By btk10 in forum Access
    Replies: 1
    Last Post: 10-23-2013, 08:15 PM
  3. Too many fields define
    By kayeper in forum Programming
    Replies: 3
    Last Post: 01-27-2012, 01:30 PM
  4. Define Table with a Variable
    By Bedsingar in forum Queries
    Replies: 3
    Last Post: 07-18-2011, 07:07 AM
  5. Where to define VBA Functions?
    By Poyan in forum Access
    Replies: 6
    Last Post: 06-24-2011, 05:20 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