How are ya ad2 . . . .
[blue]Is there [purple]a way to create the Link Child and Link Master fields[/purple] in code on the pop-up forms?[/blue]
No! Link Master/Child is for form with subform only.
For an Independent Form, [blue]to be dependent on another[/blue], it has to be synchronized by other means. There are several methods to do this. The one I present here allows [blue]synchronization even after both forms are open[/blue] (most other methods synchronize the Dependent form only on open). Goto to a record on the Independent Form and the Dependent Form synchronizes (follows along).
Now the process ([purple]don't forget to backup the database in case you want to come back to square one[/purple]).
Note: You substitute all names in [purple]
purple[/purple].
[ol][li]Open the [blue]MainForm[/blue] and remove the subforms.[/li]
[li]Save/Close the form.[/li]
[li]Make a query for each [blue]Dependent Form[/blue] (your pop-ups) with the fields you desire. Be sure to [blue]include a field common to both forms[/blue] (main & pop-up . . . usually the PrimaryKey . . . in fact thats what I use in the example code). Stay in Query Design View.[/li]
[li]In the [blue]criteria for PrimaryKey[/blue] add the following:
Forms![purple]
MainFormName[/purple]![purple]
PrimaryKeyName[/purple][/li]
[li]Save & name the query.[/li]
[li]Open the [blue]Pop-up Form[/blue] in design view and in the [blue]RecordSource[/blue] select the query from the dropdown list.[/li]
[li]Save/Close the form.[/li]
[li]The MainForm needs to detect if the Pop-up Form is open. If it is, [blue]
synchronization is performed by a simple Requery of the Pop-up![/blue] So in a module in the module window add the following code:
Code:
[blue]Function IsOpenFrm(frmName As String) As Boolean
Dim cp As CurrentProject, Frms As Object
Set cp = CurrentProject()
Set Frms = cp.AllForms
If Frms.Item(frmName).IsLoaded Then
If Forms(frmName).CurrentView > 0 Then IsOpenFrm = True
End If
Set Frms = Nothing
Set cp = Nothing
End Function[/blue]
[/li]
[li]Finally, in the [blue]On Current[/blue] event of the [blue]MainForm[/blue] add the following:
Code:
[blue] If IsOpenFrm("[purple][b]Pop-upFormName[/b][/purple]") Then
Forms!Pop-upFormName.Requery
End If[/blue]
[/li][/ol]
However you decide to open the [blue]Pop-upForm[/blue], don't do anything special, just open it (like DoCmd.OpenForm "FormName"). It'll automatically synchronize on open!
[purple]Thats it. Give it a whirl & let me know . . . .[/purple]
See Ya! . . . . . .