adding using recordset does not include linked field of subform

G

Guest

I have a list box were I can select multiple records. A command button is
supposed to add the selected records to an active form with subform. I have
the following code for the button.

Dim varItem As Variant
Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("QryOrderDetailsSubform", dbOpenDynaset)

With Me.Products
For Each varItem In .ItemsSelected
rst.AddNew
rst![ProductID] = .ItemData(varItem)
rst![OrderID] = AddanOrderandEditDetails![OrderID]
rst.Update
Next varItem
End With

rst.Close
Set rst = Nothing


The record is added but does not show in the subform because the orderID of
the active record in the form "AddanOrderandEditDetails" is not copied to the
orderID in the record set. What am I doing wrong?
 
M

Marshall Barton

LVer said:
I have a list box were I can select multiple records. A command button is
supposed to add the selected records to an active form with subform. I have
the following code for the button.

Dim varItem As Variant
Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("QryOrderDetailsSubform", dbOpenDynaset)

With Me.Products
For Each varItem In .ItemsSelected
rst.AddNew
rst![ProductID] = .ItemData(varItem)
rst![OrderID] = AddanOrderandEditDetails![OrderID]
rst.Update
Next varItem
End With

rst.Close
Set rst = Nothing


The record is added but does not show in the subform because the orderID of
the active record in the form "AddanOrderandEditDetails" is not copied to the
orderID in the record set.

To refer to a form, you need to tell Access where the name
can be found. In this case it's in the Forms colletion:

rst![OrderID] = Forms!AddanOrderandEditDetails!OrderID
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top