Now what I need it to do is loop so that their will be many records that show up. I kind of want to build a table and the records come underneath. Something like this:
Trocar Part Number Trocar Serial Number Shipper Number Customer Name
This is the code that I am using:
Function SeekOnMultiFields()
Dim rstDest1 As Recordset
Dim rstDest2 As Recordset
Dim qdf1 As QueryDef
Dim qdf2 As QueryDef
Dim dbs As Database
Dim myArray(1 To 4) As Variant
Dim strBody As String
Set dbs = CurrentDb()
Set qdf1 = dbs.QueryDefs("qry_GetShipment_To_Populate_TrocarMasterTable")
Set qdf2 = dbs.QueryDefs("qry_TrocarPartSerial")
Set rstDest1 = qdf1.OpenRecordset(dbOpenDynaset)
GetHandler:
qdf2.Parameters("trocarPart") = rstDest1!Item_Number
qdf2.Parameters("trocarSerial") = rstDest1!Lot_Serial_Number
Set rstDest2 = qdf2.OpenRecordset(dbOpenDynaset)
With rstDest2
On Error Resume Next
rstDest2.MoveLast
rstDest2.MoveFirst
If rstDest2.RecordCount > 0 Then
.Edit
rstDest2!Date_Last_Shipped = rstDest1!Ship_Date
rstDest2!Customer_Number = rstDest1!Customer_Number
rstDest2!Ship_to = rstDest1!Ship_to
rstDest2!Standard_Cost_at_First_Shipment = rstDest1!Accum_Material_Cost
.Update
Else
myArray(1) = rstDest1!Item_Number
myArray(2) = rstDest1!Lot_Serial_Number
myArray(3) = rstDest1!Shipper_Number
myArray(4) = rstDest1!Customer_Name
'MsgBox "Record Not Found"
End If
rstDest2.Close
rstDest1.MoveNext
If Not rstDest1.EOF Then
GoTo GetHandler
End If
End With
strBody = "These are the Elements that did not pass through " & vbCrLf & vbCrLf & "Trocar Part #: " & myArray(1) & vbCrLf & "Trocar Serial #: " & myArray(2) & vbCrLf & "Shipper #: " & myArray(3) & vbCrLf & "Customer Name: " & myArray(4)
DoCmd.SendObject acSendNoObject, , , "
someone@something.com", , , "Records that did not pass through", strBody, False
End Function
In
Red is where I think I need the loop.