Q:

VBA: Won't allow me to change the RecordSource of another Form in Microsoft Access

I'm working on a database that holds and displays cources for employees, every employee has a different date on which he or she has to do the specific course again. I made a few tabels that hold all the information. I can display the information in a form, this form contains a few buttons which allow me to choose between different Queries. All Queries output the same type of data in the same form. For easy reference I will call this form FormA.
This all works fine but a few hours ago I added a button which should allow me to update the information of a certain record. This updating happens in a different form lets call it FormB. In the old situation I used a specific form for every training but I thought that this was every unefficient. I made a form that can display the information of every query. The problem that i'm encountering is the fact that whenever I press the button to update a certain record. It always displays the information of the top record in the query/form. I have been stuck on this for a few hours now and I just cant get it to work. If I manually set the RecordSource of FormB to the right query it all works like it should. But this requires me to make a lot of the same forms. 
I will try to link all the code that I think is relevant. If something else is needed please say so.
The code used on the update button placed on FormA:
Private Sub btnUpdate_Click()
Dim stDocName As String

If Forms!FormA.RecordSource = "QryFG" Then

  stDocName = "FormB"

  ' we open first the form:
  DoCmd.OpenForm stDocName, , , "peoplesoftnr = " & Me!PeopleSoftNr

  ' we then set up it's RecordSource:
  Forms!FormB.RecordSource = "QryFG"

End If

This if statement is repeated five times of all the different trainings, they are all the same so I won't include them in this post.
The code fills my textboxes in my FormB. But it always picks the top record. Even when I press the button that is not in the same row (FormA). When I comment out the following line:
' Forms!FormB.RecordSource = "QryFG":

And manually set the QryFG as the RecordSource of FormB, it does what its supposed to do. But by doing this I will have to create alot of the same forms. I hope there is a better way of doing this. Thanks in advance for your time and efford. My native language is not English so please ignore the spelling and grammar mistakes ;).
Thanks again!
Joeri Rommers

A:

By setting the form's recordsource, you overwrite the filter that you previously set in DoCmd.OpenForm, so it shows all records of QryFG, starting with the first.
There are multiple ways around that, e.g.
' Open without filter
DoCmd.OpenForm stDocName
' Limit recordsource to current record
Forms!FormB.RecordSource = "SELECT * FROM QryFG WHERE peoplesoftnr = " & Me!PeopleSoftNr

or set the filter after changing the recordsource:
DoCmd.OpenForm stDocName
With Forms(stDocName)
    .RecordSource = "QryFG"
    .Filter = "peoplesoftnr = " & Me!PeopleSoftNr
    .FilterOn = True
End With

If the form "flickers" while doing that, you can open it with WindowMode:=acHidden and then set it to .Visible = True after changing RecordSource/Filter.

