Results 1 to 5 of 5
  1. #1
    Mister-B is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    31

    Get Value from first form opened

    Hi there,



    I have a simple Db with 5 nearly identical forms linked to five tables.

    At any time there will always be at least one form open. When I open a second form I would like to be able to read a value from the first form opened, irrespective of which form that may be.

    How do I go about it? I am thinking of something like Me.ID = OpenedForms(1).ID or something along those lines. In a multi tabbed form this can be done with MultiPages but does anybody know the synthax for individual forms?

    Thanks and kind regards,
    Martin

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    Could set a global variable to that value when first form opens then any form can reference that global variable. Complication is determining when variable should be replaced or set to empty.

    Or use If Then Else to test if form is open.

    If CurrentProject.AllForms("Form1Name").IsLoaded Then
    ...
    ElseIf CurrentProject.AllForms("Form2Name").IsLoaded Then
    ...
    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.

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I have a simple Db with 5 nearly identical forms linked to five tables.
    That sounds like a design issue right there.
    At any time there will always be at least one form open
    So if there are 2 open and you open a third, which form do you want to get a value from - the 1st or 2nd? And so on...
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Lhoj is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2021
    Posts
    92
    I'm understanding it's the first form opened the one he always wants to reference. Which is actually pretty simple through the Forms object. It contains the forms that are currently open in the DB. So basically Forms(0) will return the first to be opened. Be wary though that closing and reopening a form will cause it to move to the last place of the Forms list, don't know if that's the behaviour you expect.

  5. #5
    Mister-B is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    31
    Hi,

    thanks for all the suggestions. Forms(0) is the way I will go.

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

Similar Threads

  1. Replies: 6
    Last Post: 06-27-2018, 01:33 PM
  2. Replies: 18
    Last Post: 08-02-2017, 12:56 PM
  3. Replies: 5
    Last Post: 03-27-2017, 07:48 PM
  4. Replies: 5
    Last Post: 10-18-2016, 06:00 AM
  5. Replies: 9
    Last Post: 09-18-2014, 10:16 AM

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