<% 'Set the response buffer to true as we maybe redirecting Response.Buffer = True 'Dimension variables Dim rsAddNewsItem 'Database recordset to add the new News Item Dim strInputNewsTitle 'Holds the News Title Dim strInputShortNewsItem 'Holds the short news item Dim strInputNewsItem 'Holds the News Item Dim blnComments 'set to true if users can leave comments on the news item Dim lngNewsID 'Holds the News item ID number Dim strMode 'Holds whether the News Item is new or to be updated 'Read in the mode of the page and the News ID number strMode = Request.Form("mode") If strMode = "edit" Then lngNewsID = CLng(Request.Form("NewsID")) 'Read in user details from the form strInputNewsTitle = Request.Form("title") strInputShortNewsItem = Request.Form("shortNews") strInputNewsItem = Request.Form("newsItem") blnComments = CBool(Request.Form("comments")) 'Strip out Norton Internet Security add blocking code that messes up news posts strInputShortNewsItem = Replace(strInputShortNewsItem, "", "", 1, -1, 1) strInputNewsItem = Replace(strInputNewsItem, "", "", 1, -1, 1) 'If this is not the WYSIWYG editir then format the text If Request.Form("browser") <> "IE" AND Request.Form("lineBreak") = "true" Then 'Replace the vb new line code for the HTML new break code strInputShortNewsItem = Replace(strInputShortNewsItem, vbCrLf, "
") strInputNewsItem = Replace(strInputNewsItem, vbCrLf, "
") End If 'Create recorset object Set rsAddNewsItem = Server.CreateObject("ADODB.Recordset") 'If the mode is edit then initialise the SQL query to get the Nerws Item to be updated If strMode = "edit" Then strSQL = "SELECT tblNews.* FROM tblNews WHERE tblNews.News_ID = " & lngNewsID & ";" Else 'Initalise the SQL string with a query to read in all the new items from the database strSQL = "SELECT tblNews.* FROM tblNews;" End If 'Set the cursor type property of the record set to Dynamic so we can navigate through the record set rsAddNewsItem.CursorType = 2 'Set the Lock Type for the records so that the record set is only locked when it is updated rsAddNewsItem.LockType = 3 'Open the recordset rsAddNewsItem.Open strSQL, objADO 'Add a new record to the recordset if it's a new News Item If NOT strMode = "edit" Then rsAddNewsItem.AddNew rsAddNewsItem.Fields("News_title") = strInputNewsTitle rsAddNewsItem.Fields("Short_news") = strInputShortNewsItem rsAddNewsItem.Fields("News_item") = strInputNewsItem rsAddNewsItem.Fields("Comments") = blnComments 'Update the database with the new recordset rsAddNewsItem.Update 'Requery the database to make sure that the News Item has been deleted 'This will make the script wait until Database has updated itself as sometimes Access can be a little slow at updating rsAddNewsItem.Requery 'Reset Sever Objects rsAddNewsItem.Close Set rsAddNewsItem = Nothing Set adoCon = Nothing Set strCon = Nothing 'If this is an update then go back to the select news item page If strMode = "edit" then Response.Redirect "select_news_item.asp" %>
Add News Item


Your News Item has been entered into the Database.

" target="_top">Add another use news item