Sub CopyDetailsToSKPIs_SelectByTagNumber()
Dim rs As DAO.Recordset
Dim qd As QueryDef
Dim recCount As Long
Dim copyCount As Long
Dim msgString As String
Set rs = Me.qSkpiInvestigationTMMIsubform.Form.RecordsetClone
If Not ((rs.BOF) And (rs.EOF)) Then
rs.MoveLast
recCount = rs.RecordCount
Debug.Print recCount & " records in subform"
rs.MoveFirst
For ctr = 1 To rs.RecordCount
If rs.Fields("Copy") = True And rs("tagNumber") <> Me.TagNumber Then
copyCount = copyCount + 1
Debug.Print "*** Copying details to SKPI with Tagnumber " & rs.Fields("tagNumber")
Set qd = CurrentDb.QueryDefs("qryUpdateSKPI_TagNumber")
qd.Parameters("strTagNumber") = rs.Fields("tagNumber")
'Fill in the form-based params
qd.Parameters(1) = Me.DateInvestigationIssued
qd.Parameters(2) = Me.RCOccurence
qd.Parameters(3) = Me.RCDetection
qd.Parameters(4) = Me.RCCategory
qd.Parameters(5) = Me.Responsible
qd.Parameters(6) = Me.dispute
qd.Parameters(7) = Me.CMOccurence
qd.Parameters(8) = Me.CMDetection
qd.Parameters(9) = Me.CMCategory
qd.Parameters(10) = Me.DateCMImplemented
qd.Parameters(11) = Me.Status
qd.Parameters(12) = Me.WeeklyUpdate
qd.Parameters(13) = Me.WeeklyUpdateDate
' For x = 0 To qd.Parameters.Count - 1
' Debug.Print x; qd.Parameters(x).Name & vbTab & vbTab & qd.Parameters(x).Value
' Next
qd.Execute
Set qd = Nothing
ElseIf rs("tagNumber") = Me.TagNumber Then
Debug.Print "Skipping TagNumber" & rs("tagNumber") & " because it is the record being edited in the main form."
End If
rs.MoveNext
Next
msgString = "Details were copied to " & copyCount & " records."
Else
msgString = "No records in subform!"
End If
MsgBox msgString, vbOKOnly + vbInformation, "Copy to multiple SKPIs"
Set qd = Nothing
Set rs = Nothing
End Sub
|