John W. Vinson said:
Simply view the properties of the listbox and change its RowSource
property to
your choice of the name of the stored Query (assuming it's a stored query,
which might be used elsewhere in the database) or to the SQL string.
I don't think I've used a combo or listbox based on a Table in years.
Queries
let you sort, limit the fields and records included, etc.
The only downside I see is that this will be slowed down considerably by
the
repeated calls to the funGetHorse function. Any chance that you could
replace
the function by using tblHorseInfo, which is already joined to
tblInvoice_ItMdt? What does funGetHorse do?
Thanks John' it basically gives the horses name if unnamed as
Sire-Dam-Age-Sex till such time as it gets a name!
Function funGetHorse(Optional lngInvoiceID As Long = 0, Optional lngHorseID
As Long = 0, Optional bHorse As Boolean = False) As Variant
Dim recHorseID As New ADODB.Recordset, strAge As String, strName As String
Dim recHorseName As New ADODB.Recordset
If lngHorseID = 0 And lngInvoiceID = 0 Then
funGetHorse = ""
Exit Function
End If
If lngHorseID = 0 Then
recHorseID.Open "SELECT HorseID FROM tblInvoice WHERE InvoiceID=" _
& lngInvoiceID, CurrentProject.Connection, adOpenDynamic,
adLockOptimistic
If recHorseID.EOF = True And recHorseID.BOF = True Then
Set recHorseID = Nothing
funGetHorse = ""
Exit Function
End If
lngHorseID = recHorseID.Fields("HorseID")
End If
recHorseName.Open "SELECT * FROM tblHorseInfo WHERE HorseID=" _
& lngHorseID, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
If recHorseName.EOF = True And recHorseName.BOF = True Then
Set recHorseName = Nothing
funGetHorse = ""
Exit Function
End If
If IsNull(recHorseName.Fields("HorseName")) Or
recHorseName.Fields("HorseName") = "" Then
'If flg is true and Horse Name is null then Horse Name is set as
blank.
If bHorse = False Then
If IsNull(recHorseName.Fields("DateOfBirth")) Or
recHorseName.Fields("DateOfBirth") = "" Then
strAge = "0yo"
Else
strAge = funCalcAge(Format(CDate("01-Aug-" &
recHorseName.Fields("DateOfBirth")), "dd-mmm-yyyy"), Format(Now(),
"dd-mmm-yyyy"), 1)
End If
strName = Nz(recHorseName.Fields("FatherName"), "") & " -- " &
Nz(recHorseName.Fields("MotherName"), "") _
& " " & strAge & " " & Nz(recHorseName.Fields("Sex"), "")
Else
strName = ""
End If
Else
strName = recHorseName.Fields("HorseName")
End If
Set recHorseID = Nothing
Set recHorseName = Nothing
funGetHorse = strName
End Function