Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a continuous form (MasterForm) for data entry based on one table. Some records need additional data, which I want to enter in a separate popup form (which has another table behind). This popup form (SlaveForm) opens by means of a click event in the MasterForm which triggers the DoCmd.OpenForm (vba instruction).

How can I “force” the popup form (SlaveForm) to be “in line” with the last current record of the MasterForm, by VBA code, exactly as I can do in a form/subform format (but here access has explicit tools to do that)?

Edit: See uploaded example https://gofile.io/?c=VvMfiv (I am using an external link, since I was not able to find how I can do that in stackOverflow)

In the example, let us supose that we want to add Wagner's Parsifal Opera. After entering the name Parsifal you choose "Have Characters". It will open the SlaveForm (characters), where you want to write "Parsifal" and "Amfortas". However, I am not able to configure the synchronization between the MasterForm and the SlaveForm.

Any suggestion?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
277 views
Welcome To Ask or Share your Answers For Others

1 Answer

After some more digging, I manage to solve the problem. The BeforeInsert event in the slave form is the key. See uploaded file: https://gofile.io/?c=UxRdM8

In the MasterForm there is a text box (which can be set to be invisible) with the primary key (txtIDWork). After the Slave Form has been loaded, and before inserting a new register in the SlaveForm/Table, the BeforeInsert event (of the SlaveForm) assures that the primary key of the MasterForm (of the current register) is set to the foreign key of the SlaveForm:

    Private Sub Form_BeforeInsert(Cancel As Integer)
        Me.txtWorkNumber = Forms.frmMaster.txtIDWork
    End Sub

where txtWorkNumber is the text box where the foreign key is written (which can be set to be invisible).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...