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...
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:
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
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.