Results 1 to 6 of 6
  1. #1
    shylock is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Sep 2018
    Location
    Dayton, Ohio
    Posts
    100

    Passing Multiple Arguments between Forms

    I am trying to pass multiple arguments from one form to another. The code for the first form is as follows:



    Code:
     
    Private Sub txtServerNm_Click()
    Dim strSName As StringstrSName = Me.txtServerNm + "|" + Me.txtIPAddr
    Debug.Print strSName
    
        DoCmd.OpenForm "frmLogicalServerAdminSingleRec", , , , , , strSName
    End Sub
    The code form the receiving form is:

    Code:
    Private Sub Form_Load()
        Dim strVal As String
        Dim inPos As Integer
        Dim ipVal As String
         
        If Len(Me.OpenArgs) > 0 Then
            inPos = InStr(Me.OpenArgs, "|")
            
            If inPos > 0 Then
                strVal = Left$(Me.OpenArgs, inPos - 1)
                ipVal = Mid$(Me.OpenArgs, inPos + 1)
                
                Me.txtServerNm = strVal
                Me.txtIPAddr = ipVal
            End If
        End If
    End Sub
    DeBug.Print shows the expected arguments are in strSName. strSWName = Albatross|140.106.160.29

    The problem is that OpenArgs is Null in the receiving form.

    I have used this same code format in other forms and is works fine. Can anyone tell me why it doesn't work in this case?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,526
    you don't need to 'pass' them,
    all forms and objects are available using the full path name:

    forms!myForm1!txtBox1 = forms!myForm2!cboBox2

  3. #3
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Are you sure that code works to set up the string , this isn't legal syntax;
    Code:
    Dim strSName As StringstrSName = Me.txtServerNm + "|" + Me.txtIPAddr
    Try
    Code:
    Dim strSName As String
    
    strSName = Me.txtServerNm + "|" + Me.txtIPAddr
    
    Debug.Print strSName
    Edit : Or is that just a formatting error ?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Is the form being opened already open maybe, even in design view?

    Minty, the forum software often does that to me when I post code, so I'm guessing that's the cause.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    shylock is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Sep 2018
    Location
    Dayton, Ohio
    Posts
    100
    Thanks, one and all. I don't understand why having the receiving form open in design view would matter, but evidently it does. I closed the receiving form and the next time I ran the first form it successfully passed the parameters to the second form. Thanks again.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    No problem. OpenArgs are passed when the form is opened by the code. I don't know what happens under the covers, but I'd guess that since the form is already open, even in design view, the arguments are ignored. In a sense, the code isn't opening the form because it's already open, so its arguments aren't applied.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Passing arguments to a public sub
    By EonsTimE in forum Programming
    Replies: 4
    Last Post: 04-05-2016, 03:29 PM
  2. VBA passing Array arguments to procedure
    By George in forum Access
    Replies: 2
    Last Post: 05-13-2015, 10:03 AM
  3. VBA ByVal vs ByRef Passing Arguments
    By ylatodd in forum Programming
    Replies: 5
    Last Post: 10-22-2013, 02:49 PM
  4. Replies: 0
    Last Post: 04-02-2012, 11:30 AM
  5. Replies: 4
    Last Post: 06-13-2011, 12:14 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