Results 1 to 6 of 6
  1. #1
    StuartR is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Scotland
    Posts
    46

    Question Passing Args when opening a new form

    I am passing information from one form to another by creating a variable called InfoFields and then splitting the variable into various parts to assign to new fields.

    Unfortunately, the fields that I am trying to pass are different types (numbers and text) and I am getting a mismatch error when I trigger the code.

    My Code is ..

    Code:
    Private Sub AddFamilyMemberBttn_Click()
    
    'Capture info to pass to New Form
    
    Dim InfoFields as String
    
    InfoFields = Me.Family_ID + ";" + Me.Full_Name + ";" + Me.Address_Line1 + ";" + etc etc
    
    DoCmd.OpenForm "New_Fam_Mem", acNormal,,,acFormAdd,,InfoFields
    
    End Sub
    Me.Family_ID is Numeric and other fields are Text

    On my second form I split the args with the following code ..



    Code:
    Private Sub Form_Load()
    If Not IsNull(Me.OPenArgs) then
    Args = Split(Me.OpenArgs, ";")
    Me.Family_ID = CInt(Args(0))
    Me.Name = CStr(Args(1))
    etc etc
    End If
    End Sub
    This all works fine if I remove the Numeric Field, but Is there anyway of passing multiple args of diffrent types?

    Any help would be appreciated

    Stuart

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    The OpenArgs argument of the OpenForm command is *always* a string value. Convert your numeric value to a string to send. The Str() function should do that for you.

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    BTW, you should use the "&" character for concatenation of strings rather then the "+". The "+" can give you unexpected results on occasion.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Use the & for concatenation and won't need to convert numbers.

    The + is trying to sum a string and number which causes type mismatch error.

    AFAIK, there is only one situation where using + for concatenation is appropriate and that is to concatenate strings and the desire is to suppress punctuation if possibility of Null. For example, if last name will always be available but for some odd reason first name is not:

    [LastName] & ", " & [FirstName]

    will result in Jones,

    [LastName] & ", " + [FirstName]

    will result in Jones
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    StuartR is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Scotland
    Posts
    46
    Thanks all ~ "&" instead of "+" solved the issue and I didn't need to convert the numeric field.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

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

Similar Threads

  1. Replies: 5
    Last Post: 11-18-2016, 10:27 AM
  2. Replies: 5
    Last Post: 01-24-2015, 12:59 AM
  3. VBA Recordset.Update doesn' run with args ...
    By fluppe in forum Programming
    Replies: 4
    Last Post: 07-15-2014, 01:18 PM
  4. Access not passing data when opening form
    By cardgage in forum Forms
    Replies: 5
    Last Post: 12-11-2012, 06:34 AM
  5. Opening form with passing argument
    By eacollie in forum Forms
    Replies: 3
    Last Post: 06-03-2011, 09:37 AM

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