Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2004

    Question Unanswered: Linking FORMS to each other

    I have two forms that show data from two tables. On form A, I have a command button which opens form B. When I look at form A, I can see the data that applies to Mr X. When I click the button to open form B, I see the data that applies to Mrs O. I want form B to show the information for whoever was showing in form A (in this case, Mr X).

    I've tried SQL thingies, but I'm not really a pro at this...

    Any ideas?


  2. #2
    Join Date
    Apr 2004
    outside the rim
    Well, as always, there are many ways to do this, most of which are not clear or straight forward.

    Here's a few quickies that may work out for you:

    1. Use the "Open Arguments"
    When you use DoCmd.OpenForm, you'll notice that the last optional item you can add is "Open Args". This is a string of text data you can pass to the form you are opening. This would be a great place to pass the key value of the record you want to pull. Here's an example:
    DoCmd.OpenForm "mfOtherForm", , , , , , Format(Me.KeyField)
    then, in your second form, use this in the OnOpen event:
    If Len(Me.OpenArgs & "") > 0 Then
         Me.Filter = "[KeyField] = " & Me.OpenArgs
         Me.FilterOn = True
    End If
    2. Use "Public Variables"
    Many people frown on the use of public variables and there are reasons to not use them. They are a very convienent item, however, and if you just need to "get in the door" then go ahead!
    First, create a module to declare the varaible (if you're going to use public variable, always declare them in a public module - you'll save yourself a lot of headaches later)
    Public pubStrValue As String
    This line sits at the top of the module and declares a string that remains in memory across the application - meaning you can assign a value to it in one form and see that value in the other form. So, use it similar to the OpenArgs example above.

    3. You could reference the control on the first form in code on the second form, but it's risky - if the first form is not open, you'll generate an error. The context is:
    Using this, you can access the desired value directly from the first form.

    Hope this helps!
    have fun!

    Todd S.
    click to email

    Independent Development Consultant
    Biz db & reports - SQL, Access, Crystal, Seradex and more
    Small, custom, unique programs - Office, VBA, .NET

    Favorite message from Windows:
    There was an error displaying the previous error message

    Sadly, there was no error number to look up ...

  3. #3
    Join Date
    Nov 2004
    Thanks - worked a charm... I'll just sit here and click the button and grin as it works for a while before trying the next thing... Thanks heaps.

Posting Permissions

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