Results 1 to 5 of 5

Thread: [RESOLVED] Transferring Strings Between Two Forms

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    8

    Resolved [RESOLVED] Transferring Strings Between Two Forms

    In Access I have 2 Forms. Main and Secondary.
    On the Main form I have a cmdButton that opens the second form using and OpenForm command.

    I have text boxes on the main form that take user input as strings. I want to be able to transfer those strings to the secondary form for use, or at least be able to reference them, but have been unable to do so.

    I tried referencing with a line like StringVariable = Main.txtBox.Text but was unsuccessful. Any advice would be much appreciated. Thanks.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Transferring Strings Between Two Forms

    Why not just reference the controls that contain the strings?
    VB Code:
    1. Forms![Form2]![txtString2].Text = Forms![Form1]![txtString1].Text
    Or you could use a public variable in a module.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    8

    Re: Transferring Strings Between Two Forms

    Robdogg, thanks for the Reply, but a couple of questions.
    1.I would prefer to create a public variable but each form has its own module of code. So creating a public variable on one does not apply to the other as I know it. How would I do that then?
    2. In regards to the sample you posted: what does the '!' mean?
    Why did the code begin with 'Forms!' ?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Transferring Strings Between Two Forms

    1. You can create a new general Module from the Modules section in Access. Then create a Public variable of the type you need. You will now be able to access that variable from anywhere throughout Access.

    2. It starts with "Forms" because its the forms collection and we are wanting to access an item in the collection. The "!" is similar to the ".".
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    8

    Re: Transferring Strings Between Two Forms

    Ah! A new general Module... I love it!
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width