473,785 Members | 2,553 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RE: Adding filters to excel report

92 New Member
Hi folks,

I am a newbie to this functionality of creating excel report using VB/VB Script.
I have been given a code and asked to add filters to the excel sheet that is created using the below code.

Can somebody help me out in resloving the issue??


<%
Option Explicit
%>
<!--#include file="connectio n.asp"-->//DB connection string
<%
Dim sqlstr
Dim oConn,sql,rs,He aderTitle,dDate Now,sDateString ,sFileName

Const PAGE_TITLE = "Contract Database Reporting"

'download to excel
'setup filename
dDateNow = Now
sDateString = CStr(Month(dDat eNow)) & CStr(Day(dDateN ow)) & CStr(Year(dDate Now)) & CStr(Hour(dDate Now)) & CStr(Minute(dDa teNow))

sqlstr = Trim(Request.Fo rm("SQL"))

sFileName = "ContractDB_dat adump_" & sDateString & ".xls"

sql = sqlstr
'db oConnection and query

if Request.QuerySt ring("Pref") = "Yes" then
sql = "SELECT Datecreated,Ref _Num,Record_Sta tus,Agr_Model,S upplierRating,S upType,Company_ Name,Com_Group, Com_Code,Prefer redGeography,Pr eferredCountrie s,Proc_Email,St art_Date,End_Da te FROM Sample WHERE Record_Status = 'Active' AND SupplierRating LIKE 'Preferred%' Order by Company_Name Asc"
end if

Set rs = Server.CreateOb ject("ADODB.Rec ordset")
Set rs = oConn.Execute(s ql)

'call rs to excel function
Call DisplayRSInExce l(rs,"#CC0033", "#FFFFFF",sFile Name)
'cleanup
rs.Close
Set rs = Nothing
oConn.Close
Set oConn = Nothing

'-------------routines used in this page --------------------------------------------------------
'function display RS in excel format in browser
Sub DisplayRSInExce l(oRs,sHeaderBG Color,sHeaderFo ntColor,sFilena me)
Dim m, i 'number of fields, loop variable
Dim s1, s2 'work strings
Dim sCellValue
Dim sCellBGColor
Dim objExcel
Dim objMailName
'Dim sFieldVal
Dim s_RetVal

'excel header info
Response.Buffer = True
Response.Conten tType = "applicatio n/vnd.ms-excel"
Response.AddHea der "Content-Disposition", "attachment ; filename=" & sFilename

If oRs.EOF Then
Response.Write "No records match your request" & vbcrlf
Else
if Request.QuerySt ring("Pref") = "Yes" then

'create table & header cells (and border if desired)
Response.Write "<table cellpadding=""0 "" cellspacing=""0 "" border=""1"">" & vbcrlf & "<tr>" & vbcrlf

'create header
m = oRs.Fields.Coun t - 1
For i = 0 To 13

s1 = oRs.Fields(i).N ame & ""
s2 = replace(s1, "_", " ")
Response.Write "<td align=""left"" valign=""top"" bgcolor=""" & sHeaderBGColor & """><b><fon t color=""" & sHeaderFontColo r & """>" & s2 & "</font></b></td>"
Next
Response.Write "</tr>" & vbcrlf & vbcrlf

'create detail records
Do While Not oRs.EOF
Response.Write "<tr>"
For i = 0 To 13
sCellValue = oRs.Fields(i).V alue

If IsNull(sCellVal ue) Then sCellValue = ""
sCellBGColor = ""
Next
Response.Write "</tr>" & vbcrlf
oRs.MoveNext
Loop
Response.Write "</table>" & vbcrlf

Else

'create table & header cells (and border if desired)
Response.Write "<table cellpadding=""0 "" cellspacing=""0 "" border=""1"">" & vbcrlf & "<tr>" & vbcrlf

'create header
m = oRs.Fields.Coun t - 1

For i = 0 To 26

s1 = oRs.Fields(i).N ame & ""

If s1 = "ReqState" Then
Else
s2 = replace(s1, "_", " ")
Response.Write "<td align=""left"" valign=""top"" bgcolor=""" & sHeaderBGColor & """><b><fon t color=""" & sHeaderFontColo r & """>" & s2 & "</font></b></td>"
End If
Next
Response.Write "</tr>" & vbcrlf & vbcrlf

'create detail records
Do While Not oRs.EOF
Response.Write "<tr>"
For i = 0 To 26
sCellValue = oRs.Fields(i).V alue

If oRs.Fields(i).N ame = "ReqState" Then
Else

If IsNull(sCellVal ue) Then sCellValue = ""
sCellBGColor = ""

Response.Write "<td " & sCellBGColor & ">" & sCellValue & "</td>"

End If
Next
Response.Write "</tr>" & vbcrlf
oRs.MoveNext
Loop
Response.Write "</table>" & vbcrlf

End If

End If

End Sub
%>
Thanks in advance.

Regards,
Chandhseke
Dec 22 '09 #1
1 2335
chandhseke
92 New Member
P.S I want to add filters to the excel sheet that gets generated using the above code. Please help
Dec 22 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3857
by: Spacy | last post by:
Am creating a HTML Report in asp.net. To save this report to excel on client-side, i write this code: Response.ContentType = "application/vnd.ms-excel" Response.AddHeader("content-disposition", "attachment; filename=Report.xls") But once the report is saved in excel, on click of hyperlink for second html report, i dont get the second report. the same old first html report is displayed. Please can anyone help me. Am frustrated with...
1
17418
by: Steven Stewart | last post by:
I have a user who has been using Excel for a while to keep statistics and print reports. She finds using it cumbersome because of long formulas and a lot of copying and pasting. I have designed a database for her which is intended to make things a lot easier; however, I don't have a lot of experience with Access and I find that designing the reports in Access is tedious. I want to be able to print the reports (which are simply based on...
5
2801
by: MGFoster | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I've converted an ACC97 .mdb file to an ACC2K2 .adp. A report that worked in ACC97 doesn't work in ACC2K2. Report setup: ACC97 ACC2K2 (SP-2) -------------- ---------------------------
1
2638
by: jim4u | last post by:
Hi gurus, I have an automation add-in created using C# for Excel, in which I am exposing a number of functions. Is there any way I can add help-text the way excel does for other categories like Financial, Statistical, etc. The place I want my help-text to be available is in the Insert->Function. Here, we can select a category and function. The corresponding help text is displayed. Now, my automation add-in is
6
6254
by: smcdonald | last post by:
I have a report that opens up using a pretty complex query. I then pop up a form with combo boxes so the user can apply a filter to the existing report and then refresh the report. I need to export the report's records with the applied query to excel in datasheet form and it needs to contain the additional filters that the user selects. The reports datasource is the original query. Right now I have this and get the datasheet format, but I...
4
3346
by: somanyusernamesaretakenal | last post by:
What I am trying to achieve: Basically I have generated a report in access. This report needs to be updated using excel. (Updating the new data, not changing existing data) What I did was I imported the existing report into Excel (Tools – Office Links – Analyze It with MS Excel). Then I linked the report to the Excel file. (File – Get External Data – Link tables) and a link table was automatically generated. I wanted to test the link,...
5
2798
by: favor08 | last post by:
have a mainform called PendingsMain and a subform called PendingsSub. You can filter the subform by different filters and this works fine. i want to create a report that will print out the results of the users filters or print everything if there is no filters submitted within the form. Any suggestions
5
4654
by: nkechifesie | last post by:
Hi, I have written a VBA program that runs on Excel and puts data on the excel sheet. This runs everyday. I want to be adding the dates to the files, this date is gotten from the excel sheet that uploads into the report excel file. Below is the Code I wrote which doesnt work, please could you help me Sheets("Matrix sheet").Select Today = Cells(1, 1) 'The location of the date on the raw sheet Today = Format(Today,...
1
3044
by: Sport Girl | last post by:
Hi everybody , i have the task of developing in Perl a script that retrieves data from 3 tables ( bugs, profiles, products) from a MySQL database called bugs and display them in an excel sheet report. I always get when trying to test it " 500 Internal Server Error - The server encountered an internal error or misconfiguration and was unable to complete your request." Can somebody help me please.
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.