Stop some records sending table!

B

Bob Vance

I have a code that sends my "Horses" [HorseID] to a "Holding Invoices" table
tblInvoice_ItMdt
I also have a query that has my "horses" [HorseID] that dont have a owner!
What I would like to add is if HorseID is in qryHorseNoOwner to fail to send
to tblInvoice_ItMdt

Private Sub cmdCreateHoldingInvoices_Click()
On Error GoTo Err_Horse_ID_Click

Dim recInvoice_ItMdt As ADODB.Recordset
Set recInvoice_ItMdt = New ADODB.Recordset
Dim recHorseInfo As ADODB.Recordset
Set recHorseInfo = New ADODB.Recordset
Dim recTmpInvoice_ItMdt As ADODB.Recordset
Set recTmpInvoice_ItMdt = New ADODB.Recordset
Dim lngIntermediateID As Long
Dim nloop As Long


'To Save the record in alphabetical order.
recInvoice_ItMdt.Open "SELECT * FROM tblInvoice_ItMdt", cnnStableAccount,
adOpenDynamic, adLockOptimistic
For nloop = 0 To cbActiveHorses.ListCount - 1
If cbActiveHorses.Selected(nloop) = True Then
Debug.Print cbActiveHorses.Column(1, nloop) 'Prints the Horse Name
Debug.Print cbActiveHorses.Column(0, nloop) 'Prints the Horse Id
recHorseInfo_Open "Select * from tblHorseInfo where HorseID=" _
& cbActiveHorses.Column(0, nloop) & ";", cnnStableAccount,
adOpenDynamic, adLockOptimistic
If recHorseInfo.BOF = False And recHorseInfo.EOF = False Then
With recInvoice_ItMdt
If recInvoice_ItMdt.BOF = False And recInvoice_ItMdt.EOF
= False Then
.MoveLast
lngIntermediateID = Nz(.Fields("IntermediateID"), 0)
+ 1
Else
lngIntermediateID = 1
End If
.AddNew
.Fields("IntermediateID") = lngIntermediateID
.Fields("dtDate") = Format(Now, "dd/mm/yyyy")
.Fields("HorseName") = cbActiveHorses.Column(1, nloop)
.Fields("HorseID") = cbActiveHorses.Column(0, nloop)
.Fields("FatherName") =
Nz(recHorseInfo.Fields("FatherName"), "")
.Fields("MotherName") =
Nz(recHorseInfo.Fields("MotherName"), "")
.Fields("HorseDetailInfo") =
Nz(recHorseInfo.Fields("FatherName"), "") _
& "--" & Nz(recHorseInfo.Fields("MotherName"), "") &
"--" _
&
funCalcAge(Format(Nz(recHorseInfo.Fields("DateOfBirth"), "") _
, "dd-mmm-yyyy"), Format("01-Aug-" & Year(Now()),
"dd-mmm-yyyy"), 1) _
& "-" & Nz(recHorseInfo.Fields("Sex"), "")
.Fields("Sex") = Nz(recHorseInfo.Fields("Sex"), "")
.Fields("DateOfBirth") =
Nz(recHorseInfo.Fields("DateOfBirth"), "")

'Set the default value to GSTOptionText field.
.Fields("GSTOptionsText") = "Plus Tax"
.Fields("GSTOptionsValue") = 0
.Fields("SubTotal") = 0
.Fields("TotalAmount") = 0
Application.SysCmd acSysCmdSetStatus, "Horse Name=" &
..Fields("HorseName")
.Update
.Requery

End With
End If

recHorseInfo.Close

End If

Next
Me.cbActiveHorses.Requery
Application.SysCmd acSysCmdClearStatus
Forms!frmMain!cbActiveHorses.Requery
Forms!frmMain!lstModify.Requery
Exit_Horse_ID_Click:
Exit Sub

Err_Horse_ID_Click:
MsgBox "***This Horse is already in Holding Invoices***",
vbApplicationModal + vbInformation + vbOKOnly

Resume Exit_Horse_ID_Click
End Sub
 

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

Similar Threads


Top