Synchronizeing data between forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a main form with contact informations. I want the key record number
from the main form to transfer to the second form. I have created a
expression builder in the control sorce of the second form to link the key
records between data. However, when I go to run the visual basic code to
update the two forms to the main table the key record does not show up on the
second form. What am I doing wrong.
 
I have a main form with contact informations. I want the key record number
from the main form to transfer to the second form. I have created a
expression builder in the control sorce of the second form to link the key
records between data. However, when I go to run the visual basic code to
update the two forms to the main table the key record does not show up on the
second form. What am I doing wrong.

I have no idea. What are you doing?

Please post the code.

John W. Vinson[MVP]
 
Main Form: Contractor
2nd Form: CompententPerson

In the key record number on the second form I have them following in control
source:

=Forms!Contractor![Sub-Contractor]

The field is not a number. It is the name of the contractor company. In the
main form I have a control button that runs the following string:

Private Sub CmdOpenConpentent_Click()


Dim stDocName As String
Dim stLinkCriteria As String

stDocNameCompentent = "CompententPerson"
stLinkCriteria = "[Sub-Contractor]=" & "'" & Me![ContractorID] & "'"

DoCmd.OpenForm stDocNameCompentent, acNormal


End Sub

I am not sure why the name of the company does not auto fill to the second
form. The second form is not set up as a data entry. Does that effect it?
 
Dim stDocName As String
Dim stLinkCriteria As String

stDocNameCompentent = "CompententPerson"
stLinkCriteria = "[Sub-Contractor]=" & "'" & Me![ContractorID] & "'"

DoCmd.OpenForm stDocNameCompentent, acNormal


End Sub

I am not sure why the name of the company does not auto fill to the second
form. The second form is not set up as a data entry. Does that effect it?

It doesn't autofill because you're not *asking* it to autofill. You're
merely opening the "CompetentPerson" form. You are defining a local
variable named stLinkCriteria, and then not using it for anything!

You can filter the form to display existing records for that
contractor by adding a WhereCondition argument:

DoCmd.OpenForm stDocNameCompentent, acNormal, _
WhereCondition:=stLinkCriteria

Even that, though, will not automagically make new records inherit
that contractor ID. Any chance you could make CompetentPerson a
Subform on your mainform, using ContractorID as the Master Link Field
and Sub-Contractor as the Child? This would fill in automatically.

The other choice would be to pass the ID in the OpenArgs argument of
the OpenForm method and then use the form's Open argument to set the
DefaultValue property of the control bound to Sub-Contractor.

John W. Vinson[MVP]
 
Back
Top