Loop trough a recordset in the True part of IIF

  • Thread starter Thread starter Scott
  • Start date Start date
S

Scott

I have an IIF expression as follows:

IIF ((rstRef.RecordCount) > 0, IIF ((rstRef.RecordCount) = 1, vbCrLf &
vbCrLf & "Reference Number:", vbCrLf & vbCrLf & (strRef.RecordCount) & "
Reference Number(s):") & _ vbCrLf & vbCrLf & do Until rstRef.EOF &
(rstRef!ReferenceNumberCode) & " " & (rstRef!ReferenceNumberValue) & vbcrlf
& rstRef.MoveNext loop & vbcrlf, & " ") & _

But I'm getting the following compile error:

Excepted: expression

Doe's any one know how to do this.?

Thanks,

Scott
 
First of all, why you put yourself in such a visual challenge: to just read
the code is so painful, not metioning to debug it;
Secondly, you cannot concatenate string variable and VB statement; and your
VB code not even finished with " & _ " ( I guess it is due toVB editor
complains when you try to concatenate string variable and VB statement).

You can try this:

Dim str As String
If rstRef.RecordCount>0 Then
IF rstRef,RecordCount=1 Then
str=VbCrLf & VbCrLf & "Reference Number:"
ELSE
string=VbCrLf & VbCrLf & rstRef.RecordCount & "Reference Number(s):"
& VbCrlf & VbCrLf
Do Until rstRef.Eof
str=str & rst.Ref!ReferenceNumberCode & " " &
rstRef.!ReferenceNumberValue & VbCrLf
rstRef.MoveNext
Loop
End IF
End IF

I think this would be a bit easier to read logically and visually. And you
can also easily add comment between line, so some else, or yourself, can
understand what the code is doing at later time.
 
Back
Top