Unable to extract data between two dates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sausthav
    New Member
    • Nov 2008
    • 1

    Unable to extract data between two dates

    Hi All,
    I am unable to get the excel open when user select two dates from my code. Previously i was successfully extracting values by selecting year and month values from the webpage. Could you help me out in writing the Access 2003 SQL query to resolve my issue. Looking forward to your help and support:) I am giving the snapshot of my code:

    Code:
    <%@Language=VBScript%>
    
    <%
    	Dim TmplXls
    	Dim DestXls
    	Dim DB
    	Dim DBConn
    	Dim DestXlsConn
    	Dim FSO
    	Dim XlsRS
    	Dim DBRS
    	Dim sqlText
    	Dim strMnth
    	Dim strYear
    	Dim strlte10Pcnt
    	Dim cnt1
    	Dim cnt2
    	Dim cnt3
    
    
    		
    	If Request.Form("Fst").Count = 0 Then
    	strStartDate = "(Fst = Format([date],'ddmmyyyy'))"
    	Else
    		For cnt2 = 1 to Request.Form("Fst").Count
    			If cnt2 = 1 Then
    				strStartDate = "(Fst = " & Request.Form("Fst")(cnt2)
    			Else
    				strStartDate = strStartDate & " OR Fst = " & Request.Form("Fst")(cnt2)
    			End If
    	Next
    		strStartDate = strStartDate & ")"
    	End If
    
    	If Request.Form("Lst").Count = 0 Then
    		strLastDate = "(Lst = Format([date],'ddmmyyyy'))"
    	Else
    		For cnt3 = 1 To Request.Form("Lst").Count
    		If cnt3 = 1 Then
    				strLastDate = "( Lst = " & Request.Form("Lst")(cnt3)
    			Else
    				strLastDate = strLastDate & " OR Lst = " & Request.Form("Lst")(cnt3)
    			End If
    		Next
    		strLastDate = strLastDate & ")"
    	End If
    	
    	
    	
    	
    	'Response.Write strYear
    	
    	TmplXls = Server.MapPath(".") & "\Memory_Use_Sample.xls"
    	DestXls = Server.MapPath(".") & "\Memory_Use.xls"
    	DB = Server.MapPath(".") & "\Server_Monitoring.mdb"
    	
    	Set FSO = Server.CreateObject("Scripting.FileSystemObject")
    	FSO.GetFile(TmplXls).Copy DestXls
    	
    
    	Set FSO = Nothing
    
    	Set DestXlsConn = Server.CreateObject("ADODB.Connection")
    	DestXlsConn.Open "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " & DestXls & "; " & "Extended Properties=""Excel 8.0;HDR=NO;"""
    
    	Set XlsRS = Server.CreateObject("ADODB.Recordset")
    	'XlsRS.Open "Select * from Report_Range", DestXlsConn, 1, 3
    	XlsRS.Open "Select * from Memory_Use", DestXlsConn, 1, 3
    
    	Set DBConn = Server.CreateObject("ADODB.Connection")
        Set DBConn = Server.CreateObject("ADODB.Connection")
    	DBConn.Open "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " & DB
        
    	Set DBRS = Server.CreateObject("ADODB.Recordset")
    	sqlText = "Select date, Time_Hour, ServerName, MemoryUse from Q1 where date between" & strStartDate
    	 	
    	'strSQL = "SELECT * " & _ 
            ' "FROM [RECORDS] " & _ 
             '"WHERE (CDate(Date_Pur) Between #" & _ 
            ' Format(Date_From,"m/d/yyyy") & "# And #" & _ 
            ' Format(Date_To,"m/d/yyyy") & "#)" 
    	
       'Response.Write strText
      ' Response.End
    		If Request.Form("Lst").Count > 0 Then
    			sqlText = sqlText & " AND "& strLastDate 
            End If
    			
    	'Response.Write sqlText
    	'Response.End
    		
    	DBRS.Open sqlText, DBConn, 1
    	 'Response.Write sqlText	
         'Response.End	
    
           	If DBRS.Recordcount > 0 Then
    		DBRS.MoveFirst
    
    		Dim x, y
    		x = 1
    		Do While Not (DBRS.EOF)
    			XlsRS.AddNew
    			XlsRS.Fields(0).Value = x
    		
    			For y = 1 To 4
    				XlsRS.Fields(y).Value = DBRS.Fields(y-1).Value
    			Next
    			XlsRS.Update
    			DBRS.MoveNext
    			x = x + 1
    		Loop
    
    	    Response.Write "<META HTTP-EQUIV=""REFRESH"" Content=""0;URL=Memory_Use.xls"">"
    		'Response.Write "Matching records found"
    
    	Else
    		Response.Write "No matching records found"
    	End If	
    	
    	
    	DBRS.Close
    	Set DBRS = Nothing
         
        DBConn.Close
    	Set DBConn = Nothing
    	
    	DestXlsConn.Close
    	Set DestXlsConn = Nothing
    
        'Response.Write "<META HTTP-EQUIV=""REFRESH"" Content=""0;URL=Memory_Use.xls"">"
    	'XlsRS.Close
    	
    	'Set XlsRS = Nothing
    %>
    Last edited by DrBunchman; Nov 4 '08, 10:28 AM. Reason: Added [Code] Tags - Please use the '#' button
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    Originally posted by sausthav
    Hi All,
    I am unable to get the excel open when user select two dates from my code. Previously i was successfully extracting values by selecting year and month values from the webpage. Could you help me out in writing the Access 2003 SQL query to resolve my issue. Looking forward to your help and support:) I am giving the snapshot of my code:
    So what part doesn't work? Are you getting a syntax error when you query the db? Try doing a response.write of the query from the working version and from the current broken version, I bet you will see an obvious difference. If you don't please post both versions of the query (like it looks when finished).

    Jared

    Comment

    Working...