G
Guest
Thanks Graham, apart from me changing some names for controls and objects. It
worked like magic. Below is the code again u gave me.
"A bit of the old Kiwi Ingenuity"
Now I have a query that incoporates planting information, application of
operations information and the products (spary chemicals) used.
I would like to use the same values supplied from txtApplicationDate,
cboOperations, lstPlantings and lstProducts as parameter values to send the
currently viewed selection to a report.
I may need a different / new command button to for this purpose.
On my report design, I have OperationID header to hold operations info and
PlantingDetailsID Header/Footer to hold selected planting details
and would like to display the selected products on the details section.
Here is the the code that Graham gave me which is working to append records
to my tblApplication and tblApplicationDetails.
Private Sub btnAppend_Click()
Dim db As DAO.Database
Dim rsApplication As DAO.Recordset
Dim rsApplicationDetails As DAO.Recordset
Dim vPlanting As Variant
Dim vProduct As Variant
Dim lApplicationID As Long
Set db = CurrentDb
Set rsApplication = db.OpenRecordset("tblApplications")
Set rsApplicationDetails = db.OpenRecordset("tblApplicationDetails")
For Each vPlanting In lstPlantings.ItemsSelected
With rsApplication
.AddNew
!ApplicationDate = txtApplicationDate
!OperationID = cboOperation
!PlantingDetailsID = lstPlantings.ItemData(vPlanting)
lApplicationID = !ApplicationID
.Update
End With
For Each vProduct In lstProducts.ItemsSelected
With rsApplicationDetails
.AddNew
!ApplicationID = lApplicationID
!ProductID = lstProducts.ItemData(vProduct)
.Update
End With
Next vProduct
Next vPlanting
rsApplication.Close
rsApplicationDetails.Close
End Sub
worked like magic. Below is the code again u gave me.
"A bit of the old Kiwi Ingenuity"
Now I have a query that incoporates planting information, application of
operations information and the products (spary chemicals) used.
I would like to use the same values supplied from txtApplicationDate,
cboOperations, lstPlantings and lstProducts as parameter values to send the
currently viewed selection to a report.
I may need a different / new command button to for this purpose.
On my report design, I have OperationID header to hold operations info and
PlantingDetailsID Header/Footer to hold selected planting details
and would like to display the selected products on the details section.
Here is the the code that Graham gave me which is working to append records
to my tblApplication and tblApplicationDetails.
Private Sub btnAppend_Click()
Dim db As DAO.Database
Dim rsApplication As DAO.Recordset
Dim rsApplicationDetails As DAO.Recordset
Dim vPlanting As Variant
Dim vProduct As Variant
Dim lApplicationID As Long
Set db = CurrentDb
Set rsApplication = db.OpenRecordset("tblApplications")
Set rsApplicationDetails = db.OpenRecordset("tblApplicationDetails")
For Each vPlanting In lstPlantings.ItemsSelected
With rsApplication
.AddNew
!ApplicationDate = txtApplicationDate
!OperationID = cboOperation
!PlantingDetailsID = lstPlantings.ItemData(vPlanting)
lApplicationID = !ApplicationID
.Update
End With
For Each vProduct In lstProducts.ItemsSelected
With rsApplicationDetails
.AddNew
!ApplicationID = lApplicationID
!ProductID = lstProducts.ItemData(vProduct)
.Update
End With
Next vProduct
Next vPlanting
rsApplication.Close
rsApplicationDetails.Close
End Sub