Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: Excluding field in 'For Each oField in oRecordset.Fields


Message #1 by REdwards@c... on Wed, 18 Sep 2002 17:24:27
I have some code that loops through a recordset like this:

Do While Not oRecordset.EOF	
    i = 0
    For Each oField In oRecordset.Fields			
    sInfEvents = sInfEvents & "<tr><td width='5%'>"
    If i = 0 Then sInfEvents = sInfEvents & "<b> -> "
    sInfEvents = sInfEvents  & "</td><td width='95%'>" 
    If i = 0 Then sInfEvents = sInfEvents & "<b>"
    sInfEvents = sInfEvents & oField.Value & "</td></tr>"
			
    i = i + 1
Next

I want to exclude one field because there is something I want to do in 
the 'Next' portion of the code with it...

To be more direct, the field I want to exclude is a web address field. 
Originally it was to just be listed - which was fine. Now they changed to 
it being linked. I did that in the 'Next' portion of the code but of 
course it is still listed in the loop. 

How can I either exclude it in the loop, or more far-fetched, link it in 
the loop?

I hope I have explained this clearly, it might be a little hard to 
understand.

Thanks

Robert
Message #2 by Imar Spaanjaars <Imar@S...> on Wed, 18 Sep 2002 18:22:59 +0200
Hi Robert,

If I understand the situation correctly, there are (at least) two ways to 
solve this:

Method 1. Skip the field you don't want

For Each oField In oRecordset.Fields
         If Not UCase(oField.Name) = "WEBADDRESS" Then
                 ' Rest of your code here
         End If
Next

This methods checks the name of the field in the database. If the field 
contains the item to be linked (I used WebAddress as an example), simply 
skip it.


Method 2. Directly apply formatting / linking to the item:

For Each oField In oRecordset.Fields
         Select Case UCase(oField.Name)
                 Case "WEBADDRESS"
                         MyLink = MakeLink(oField.Value)

                 Case "ANOTHERFIELD"
                         ' Other actions....
                 Case Else
                         ' All other fields
         End Select
Next

Public Function MakeLink (ByVal sItemToLink)
         ' Linking code here
         MakeLink = "MyLinkedItem"
End Function


HtH, and if not, let me know.


Imar



At 05:24 PM 9/18/2002 +0000, you wrote:
>I have some code that loops through a recordset like this:
>
>Do While Not oRecordset.EOF
>     i = 0
>     For Each oField In oRecordset.Fields
>     sInfEvents = sInfEvents & "<tr><td width='5%'>"
>     If i = 0 Then sInfEvents = sInfEvents & "<b> -> "
>     sInfEvents = sInfEvents  & "</td><td width='95%'>"
>     If i = 0 Then sInfEvents = sInfEvents & "<b>"
>     sInfEvents = sInfEvents & oField.Value & "</td></tr>"
>
>     i = i + 1
>Next
>
>I want to exclude one field because there is something I want to do in
>the 'Next' portion of the code with it...
>
>To be more direct, the field I want to exclude is a web address field.
>Originally it was to just be listed - which was fine. Now they changed to
>it being linked. I did that in the 'Next' portion of the code but of
>course it is still listed in the loop.
>
>How can I either exclude it in the loop, or more far-fetched, link it in
>the loop?
>
>I hope I have explained this clearly, it might be a little hard to
>understand.
>
>Thanks
>
>Robert

Message #3 by REdwards@c... on Wed, 18 Sep 2002 18:15:42
I used a combination in a way. 

If oField.Name = "Website" Then 
sInfEvents = sInfEvents & "<a href..."


Thanks

Robert

  Return to Index