Is there a way to determine how many variables does OpenArgs contain?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TravelingCat
    New Member
    • Feb 2010
    • 82

    Is there a way to determine how many variables does OpenArgs contain?

    Hi, that is basically my question there in the title
    If someone knows..
  • Megalog
    Recognized Expert Contributor
    • Sep 2007
    • 378

    #2
    The OpenArgs property of a form/report is just a string which value is set by (usually) using a DoCmd.OpenForm/OpenReport command. It can contain multiple variables in the string, if that's what you place there. Parsing those variables out can be done with custom functions, or maybe even the Split() command.

    You'll need to be a lot more detailed with your questions if you want any further help.

    Comment

    • TravelingCat
      New Member
      • Feb 2010
      • 82

      #3
      Thanks for replying, Megalog
      Sorry if i wasn't clear, but i wasn't asking how the OpenArgs works, i know how to use it. My question was, presuming i already used it and passed several variables, once i 'catch' this OpenArgs string - is there a way to know how many variables were passed in it originally (=how many variables does openargs contain).
      It's not that important, i just wanted to know if it can be done...

      Comment

      • Megalog
        Recognized Expert Contributor
        • Sep 2007
        • 378

        #4
        OpenArgs is a temporary variable, that as far as I know, is only stored in memory while that form is open. There is no history to it, etc. You're able to play with whatever data is currently in there at that moment, that's it. So, there is only 1 variable at any time.

        Comment

        • gershwyn
          New Member
          • Feb 2010
          • 122

          #5
          Originally posted by TravelingCat
          Thanks for replying, Megalog
          Sorry if i wasn't clear, but i wasn't asking how the OpenArgs works, i know how to use it. My question was, presuming i already used it and passed several variables, once i 'catch' this OpenArgs string - is there a way to know how many variables were passed in it originally (=how many variables does openargs contain).
          It's not that important, i just wanted to know if it can be done...
          Like Megalog stated, the OpenArgs parameter is a single string variable that is passed to the form or report. If you are passing multiple values through it, then you must be combining those values into a string. The method you use to determine how many values it contains depends entirely on the method you used to combine them in the first place.

          If you want to post the code you used to pass the values, I'm sure someone can show you a way to count the values OpenArgs contains. Without seeing the calling code though, there isn't anything more to be said.

          Comment

          • missinglinq
            Recognized Expert Specialist
            • Nov 2006
            • 3533

            #6
            Assuming you're doing this way it's usually done, with a delimiting character between each item you're passing, you could do this:
            Code:
            Dim vars As Integer
            
            If Not IsNull(Me.OpenArgs) Then
            
            If InStr(Me.OpenArgs, ";") = 0 Then
               vars = 1
            Else
              vars = Len(Me.OpenArgs) - Len(Replace(Me.OpenArgs, ";", "")) + 1
            End If
            
            End If


            This assumes you're using a semi-colon as the delimiting character. You can modify for another character, if need be.

            Welcome to Bytes!

            Linq ;0)>

            Comment

            • TravelingCat
              New Member
              • Feb 2010
              • 82

              #7
              missinglinq, thanks a lot, that is exactly what i needed:) Indeed i used ";" as a delimiter, so the code does what i asked for.
              Thanks for other replies also

              Comment

              • DataAnalyzer
                New Member
                • May 2010
                • 15

                #8
                You can simply use the Split command for the OpenArgs value which will assign the results to an array (0 based). You can then use the UBound command to figure out the number of variables.

                Code:
                Dim astrValues() As String
                If Not IsNull(Me.OpenArgs) Then
                  astrValues = Split(Me.OpenArgs, ";")
                  intVars = UBound(astrValues) + 1
                End If
                Last edited by DataAnalyzer; May 9 '10, 03:04 PM. Reason: code formatting

                Comment

                • ADezii
                  Recognized Expert Expert
                  • Apr 2006
                  • 8834

                  #9
                  The following Function, in a Form Module will return either the Number of Arguments passed, NULL, or a Descriptive Error Message.
                  Code:
                  Private Function fNumberOfArgs() As Variant
                  On Error GoTo Err_fNumberOfArgs
                  
                  fNumberOfArgs = UBound(Split(Me.OpenArgs, ";")) + 1
                    
                  Exit_fNumberOfArgs:
                    Exit Function
                  
                  Err_fNumberOfArgs:
                    If Err.Number = 94 Then       'No OpenArgs
                      fNumberOfArgs = Null
                    Else
                      MsgBox Err.Description, vbExclamation, "Error in fNumberOfArgs()"
                        Resume Exit_fNumberOfArgs
                    End If
                      Resume Exit_fNumberOfArgs
                  End Function

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32633

                    #10
                    Originally posted by TravelingCat
                    TravelingCat: Hi, that is basically my question there in the title
                    If someone knows..
                    It is clearly important in this case to explain that you are passing multiple items across as a delimited string. I'm sure it saved you some time not including that info, but it's equally clear that it took up the time of various others trying to help you, to work out what you should have made clear in your question in the first place. Please try to be more specific with your questions in future.

                    Administrator.

                    Comment

                    • TravelingCat
                      New Member
                      • Feb 2010
                      • 82

                      #11
                      NeoPa, i assure you that i did not NOT mention it because i was trying to save time, but of sheer belief that the question was clear. But i explained myself immediately after the first reply, so again, sorry for vagueness.

                      Comment

                      • NeoPa
                        Recognized Expert Moderator MVP
                        • Oct 2006
                        • 32633

                        #12
                        If you're happy you did the best you could in the circumstances then I'm happy.

                        In truth, clear communication is difficult at the best of times, which is why I try to encourage care wherever possible.

                        Comment

                        • TravelingCat
                          New Member
                          • Feb 2010
                          • 82

                          #13
                          And i agree with you. But in this case, it seems like you are a little bit too hursh on me.
                          I suggest we leave it at that.

                          Comment

                          • NeoPa
                            Recognized Expert Moderator MVP
                            • Oct 2006
                            • 32633

                            #14
                            You are funny :)

                            Comment

                            • TravelingCat
                              New Member
                              • Feb 2010
                              • 82

                              #15
                              Funny is a great quality, i'll take it

                              Comment

                              Working...