I need to select the whole recordset that has the greatest date value in the "DatePosted" column. This works, but if there is no value there, or there is only one recordset I get an error... What is a better way of doing this?
Code:
Sub LastPost()
Dim RsLastPost : Set RsLastPost = Server.CreateObject("ADODB.RecordSet")
RsLastPost.Open "Select * From Posts Where ForumID="&SubCat("SubCatID")&" Order by DatePosted Asc",ObjConn,1,2
RsLastPost.MoveLast
Dim DatePosted : DatePosted = Split(RsLastPost("DatePosted")," ", -1,1)
Response.Write("<Strong>"&DatePosted(0)&"</Strong>: "&DatePosted(1)&" "&DatePosted(2)&"")
Response.Write("<br>")
Response.Write("By: <a class=LinkTableText href=profile.asp?UserName="&RsLastPost("UserName")&">"&RsLastPost("UserName")&" </a>")
Response.Write("<a href=topic.asp?TopicID="&RsLastPost("TopicID")&"&ForumID="&RsLastPost("ForumID")&"><img src=/images/icon_lastpost.gif border=0></a>")
RsLastPost.Close
Set RsLastPost = Nothing
End Sub