Opening a pop up form and linking them via a field on the main form

Seph

Member
Local time
Today, 12:41
Joined
Jul 12, 2022
Messages
72
Good day internet geniuses.

Please can you assist.

I have a form InvoiceSalesF, with a continuous subform that displays records in the cost table CostT.
(Forms are linked via InvoiceID)

1669638764881.png


I have a button that opens up a pop up form that's control source is the Cost table CostT.


1669638938686.png


The greyed out field is a usually hidden field called InvoiceID.
(Tables are linked via a one-to-many relationship)

I'm trying to open the pop up form and have it insert the main form's InvoiceID automatically so I can add records that are linked to the Invoice.

The current VBA code I'm using is:

Private Sub NewCostB_Click()

DoCmd.OpenForm "InvoiceSalesCostSF", , , "InvoiceID=" & InvoiceID

End Sub


However nothing reflects as there isn't a record captured yet in the CostT.

Any idea's would be appreciated.

P.s. I wasn't sure how to title this questions, so I will gladly change the title after some guidance.
 
The easiest route is to use the openargs property, then in the pop-up form load use that to populate the required field(s).


You can pass multiple values by building a suitable separator and them splitting it within the pop-up form loading routine.
Something like

Code:
Dim sArgs as String

SArgs = Me.InvoiceID & "|" & Me.SomeOtherField

DoCmd.OpenForm "InvoiceSalesCostSF", , , , , , sArgs
 
The easiest route is to use the openargs property, then in the pop-up form load use that to populate the required field(s).


You can pass multiple values by building a suitable separator and them splitting it within the pop-up form loading routine.
Something like

Code:
Dim sArgs as String

SArgs = Me.InvoiceID & "|" & Me.SomeOtherField

DoCmd.OpenForm "InvoiceSalesCostSF", , , , , , sArgs

Thank you very much. I will look into this
 
I think the second part of this is missing. Once the new form is open, you have to do something with the OpenArgs. This can be done in the pop up forms, before update event.
Me.InvoiceID = me.OpenArgs

Also open the form ACDIALOG window mode. That stops the code execution in the calling form. Then after the calling form's Docmd.OpenForm add a
me.recordset.requery
this will then show the new added cost record.
 
Thank you kind souls for pointing me in the correct direction and the example VBA codes.

It worked perfectly.
 

Users who are viewing this thread

Back
Top Bottom