Hi,
What's hapenning is that the SurveyID which you are passing in Session variable does not have any Questions as yet in the table and so Null is returned.
Please change Max(QuestionNum) to Isnull(Max(QuestionNum),0)
as below:
//Select the max QuestionNum where SurveyID=SurveyID
sql = "SELECT isnull(MAX(QuestionNum),0) FROM Question WHERE SurveyID='" & Session("sSurveyID") & "'"
Regards,
Nitin