Add to a String Help

  • Thread starter Thread starter Bob Vance
  • Start date Start date
B

Bob Vance

This is what I have so far but sometimes Horses have not got a HorseName yet
so I would like the Father,Mother,Sex to show instead!
idHorse = Nz(Me.tbHorseID, 0)
If idHorse <> 0 Then
strHorse = Nz(DLookup("[HorseName]", "tblHorseInfo", "[HorseID]=" &
idHorse), "")
Else
strHorse = ""
End If
------------------------------------

But if "[HorseName]" = ""
strHorse = Nz(DLookup("[FatherName]", "tblHorseInfo", "[HorseID]=" &
idHorse), "") &
strHorse = Nz(DLookup("[MotherName]", "tblHorseInfo", "[HorseID]=" &
idHorse), "") &
strHorse = Nz(DLookup("[Sex]", "tblHorseInfo", "[HorseID]=" & idHorse), "")
 
This is what I have so far but sometimes Horses have not got a HorseName yet
so I would like the Father,Mother,Sex to show instead!
idHorse = Nz(Me.tbHorseID, 0)
    If idHorse <> 0 Then
        strHorse = Nz(DLookup("[HorseName]", "tblHorseInfo", "[HorseID]=" &
idHorse), "")
    Else
        strHorse = ""
    End If
------------------------------------

But if "[HorseName]" = ""
 strHorse = Nz(DLookup("[FatherName]", "tblHorseInfo", "[HorseID]="&
idHorse), "") &
 strHorse = Nz(DLookup("[MotherName]", "tblHorseInfo", "[HorseID]="&
idHorse), "") &
 strHorse = Nz(DLookup("[Sex]", "tblHorseInfo", "[HorseID]=" & idHorse), "")

Here's the structure for the Sire/Dam part...
http://www.allenbrowne.com/ser-06.html

then the query should do what you want...
 
Thanks Peter but i will run a query from this that will give either name or
breeding
Thanks Bob

Function funGetHorseName(lngInvoiceID As Long, lngHorseID As Long) As String

Dim recHorseName As New ADODB.Recordset, strAge As String, strName As String

recHorseName.Open "SELECT * FROM tblInvoice WHERE InvoiceID=" _
& lngInvoiceID & " AND HorseID=" & lngHorseID,
CurrentProject.Connection, adOpenDynamic, adLockOptimistic
If recHorseName.EOF = True And recHorseName.BOF = True Then
Set recHorseName = Nothing
funGetHorseName = ""
Exit Function
End If

If IsNull(recHorseName.Fields("DateOfBirth")) Or
recHorseName.Fields("DateOfBirth") = "" Then
strAge = "0yo"
Else
strAge = funCalcAge(Format("01-Aug-" &
Year(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"), "")

Set recHorseName = Nothing
Debug.Print strName

funGetHorseName = strName

End Function
This is what I have so far but sometimes Horses have not got a HorseName
yet
so I would like the Father,Mother,Sex to show instead!
idHorse = Nz(Me.tbHorseID, 0)
If idHorse <> 0 Then
strHorse = Nz(DLookup("[HorseName]", "tblHorseInfo", "[HorseID]=" &
idHorse), "")
Else
strHorse = ""
End If
------------------------------------

But if "[HorseName]" = ""
strHorse = Nz(DLookup("[FatherName]", "tblHorseInfo", "[HorseID]=" &
idHorse), "") &
strHorse = Nz(DLookup("[MotherName]", "tblHorseInfo", "[HorseID]=" &
idHorse), "") &
strHorse = Nz(DLookup("[Sex]", "tblHorseInfo", "[HorseID]=" & idHorse),
"")

Here's the structure for the Sire/Dam part...
http://www.allenbrowne.com/ser-06.html

then the query should do what you want...
 
Back
Top