Results 1 to 9 of 9
  1. #1
    S2000magician is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2019
    Posts
    31

    Passing information from one form to another


    I have a form in which the user can choose to create a portfolio.

    If the user chooses to create a portfolio, I want to open a new form from which the user can choose the securities (and percentages of portfolio value) to include in the portfolio. To do so, I need to get some information from the original form for the new form.

    Is there a straightforward way to pass information from the calling form to the new form? I could make a temporary table that contains the information, but if I can pass the information without having to create an extraneous table, I'd prefer that.

    Thanks!

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Use the Open Args property of the code line that opens the new form:
    https://docs.microsoft.com/en-us/off....form.openargs

    I could have just written some pseudo code but thought you might be interested in the site. Tons of properties and events listed there.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    S2000magician is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2019
    Posts
    31
    That's exactly what I needed.

    I think.

    I'm having a devil of a time accessing the OpenArgs in the new form; everything I try gives me a null.

    I've tried Forms![Create New Portfolio Form].OpenArgs. ("Create New Portfolio Form" is the name of the new form being opened.)

    I've tried Me.OpenArgs.

    I've tried DoCmd.OpenForm with the arguments in parentheses, and I've tried it with the arguments not in parentheses. In parentheses, it complains that I'm missing expressions or equal signs or whatever. Either way, it still doesn't work.

    I think that I tried a couple of other things, but they're all giving me null.

    Sigh.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    re I've tried Forms![Create New Portfolio Form].OpenArgs. ("Create New Portfolio Form"...
    To use the OpenArgs property, open a form by using the OpenForm method of the DoCmd object and set the OpenArgs argument to the desired string expression.
    So what the heck is the DoCmd object you say? Then at that site you look up the DoCmd object and its methods, one of which is Openform as was stated in red.
    OpenForm (FormName, View, FilterName, WhereCondition, DataMode, WindowMode, OpenArgs)
    The info tells you which are optional and which are not.
    Thus
    DoCmd.OpenForm "yourFormName",,,,,,"New P Form" << best to keep it short and simple.
    Then in new form load event,
    If Me.OpenArgs = "New P Form" Then....

    P.S. commas usually have to be used even though the optional(s) is/are left out.
    Last edited by Micron; 08-17-2019 at 08:09 AM.

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Quote Originally Posted by S2000magician View Post

    ...To do so, I need to get some information from the original form for the new form...
    Is this 'some information' one piece from the original Form, two pieces or several/many pieces?

    Using OpenArgs can be reasonably used for one or two pieces...but for more that that you really have to leave the original Form open and then refer to the various Controls on it that contain the desired info.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  6. #6
    S2000magician is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2019
    Posts
    31
    That looks exactly like what I'm doing.

    Here's what I have in the calling form:

    DoCmd.OpenForm "Create Model Portfolio Form", , , , , , "ABC:XYZ"

    Here's what I have for the form being called:

    Private Sub Form_Open(Cancel As Integer)

    Dim inputinfo As String

    inputinfo = Me.OpenArgs()

    End Sub

    (I've also tried it without the parentheses.)

    What I get for Me.OpenArgs is null.

    If you can figure out what I'm doing that's stupid, I'd be ever so grateful.

    Thanks!

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Other than an extra space after the last comma, I see nothing wrong with what you show
    Code:
    DoCmd.OpenForm "Create Model Portfolio Form", , , , , , "ABC:XYZ"
    
    Private Sub Form_Open(Cancel As Integer)
    Dim inputinfo As String
    
      inputinfo = Me.OpenArgs
    
    End Sub
    If written as ...OpenArgs() that is how you write a function named OpenArgs, which would be incorrect.

    Suggestions:
    1) create 2 new forms frmOne with only a command button and frmTwo with nothing. Create a button event to open frmTwo with open args of "Hello" and replicate the form open event for frmTwo with a message box: Msgbox Me.OpenArgs. If you save both, close frmTwo and click button and frmTwo opens and you get the message, your other opening form may be corrupt. I'm assuming your posted code is exactly the same as the real code. It is best to copy and paste code AND use code tags (# on forum menubar). Not only is tagged code easier to read, bad things can happen to long lines of code when not used.
    2) if corruption is suspected, create a new form (or use frmTwo) and try copying/pasting all the controls from old to new.
    3) post a zipped copy of your db for examination
    4) adopt a proper naming convention and eliminate many of the problems associated with what you're now doing. Create Model Portfolio Form is too long but worse, contains spaces. I suspect you have object names with special characters somewhere as well (-,*,%,$,# etc.) See
    Naming conventions - http://access.mvps.org/access/general/gen0012.htm
    https://www.access-programmers.co.uk...d.php?t=225837

    What not to use in names - http://allenbrowne.com/AppIssueBadWord.html

  8. #8
    S2000magician is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2019
    Posts
    31
    Today it's working, without any changes.

    I don't know why, but at this stage I also don't care.

    Note that the parentheses after Me.OpenArgs don't seem to matter. (In one on-line reference they had the parentheses; in another they did not.)

    Thanks for all your help, even though I'm not sure why it worked.

  9. #9
    S2000magician is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2019
    Posts
    31
    Two pieces of information: both strings.

    I'm concatenating them into a single string with a colon between them (e.g., "ABC:123"); I can parse the string in the new form.

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

Similar Threads

  1. Replies: 17
    Last Post: 02-25-2018, 02:37 AM
  2. Replies: 12
    Last Post: 04-14-2017, 03:17 PM
  3. Replies: 5
    Last Post: 11-18-2016, 10:27 AM
  4. Replies: 3
    Last Post: 05-02-2014, 09:27 AM
  5. Replies: 5
    Last Post: 04-03-2011, 10:24 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