Hi,
I want to be able to select which fields the SQL statement will query data from. So the user would choose a few drop down boxes and pass the params directly into the SQL statement. Is this possible? I can't seem to figure it out.
Below is an example of what I have. Basically if I wanted to replace one of the hard coded fields, ie. Employees.[FirstName], with a selection from my criteria.html form of Employees.[FirstName] instead, how would it work?
Thanks for any help!
Derek
ps. sorry if I'm not making things clear.
Criteria.html Form
<html>
<body>
Select criteria:<p>
<form method="post" action="result.asp">
Choose a field to query:
<select name = "field1">
<option selected>Employees.[Title]
<option>Employees.[FirstName]
<option>Employees.[HireDate]
</select><p>
<input type = "submit" value = "Search">
<input type = "reset" value = "Reset Form">
</form>
</body>
</html>
result.asp
<%Option Explicit%>
<!--METADATA TYPE="TypeLib"
FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->
<html>
<head>
<Title>Northwind Customers</Title>
<link rel = "stylesheet" type = "text/css" href = "myStyle.css">
</head>
<body>
<h1 align="center">Northwind Employees</h1>
<div align = "center">
<table border = "1" bordercolor = "navy" cellpadding = "5" cellspacing = "0" bgcolor = "lightyellow">
<!-- Begin ASP code -->
<%
Dim myConn, rsEmployee, strEmployees, fielda
Set myConn = Server.CreateObject("ADODB.Connection"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
'Use a DSN to connect to northwind.mdb
myConn.Open "DSN=Northwind","Admin",""
Set rsEmployee = Server.CreateObject("ADODB.Recordset"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
'Create the big Select statement
strEmployees = "SELECT Employees.[FirstName], Employees.[HireDate], Employees.[Title] " _
& "FROM Employees " _
& "ORDER BY Employees.[FirstName]"
rsEmployee.Open strEmployees,myConn,adOpenForwardOnly,adLockReadOnly
Dim Fname,Lname,region,hireDate,Title
If not rsEmployee.BOF then
Response.Write("" _
& "<tr bgcolor = ""pink"">" _
& "<td>" _
& "First Name" _
& "</td>" _
& "<td>" _
& "Title" _
& "</td>" _
& "<td>" _
& "Hire Date" _
& "</td>" _
& "</tr>"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
Do While Not rsEmployee.EOF
Fname = rsEmployee.Fields("FirstName"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
Lname = rsEmployee.Fields("LastName"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
hireDate = rsEmployee.Fields("HireDate"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
Title = rsEmployee.Fields("Title"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
'Output content data from fields Fname, hireDate and Title
Response.Write("" _
& "<tr>" _
& "<td>" _
& Lname & ", " & Fname _
& "</td>" _
& "<td>" _
& Title _
& "</td>" _
& "<td>" _
& hireDate _
& "</td>" _
& "</tr>"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
rsEmployee.MoveNext
Loop
Else
Response.Write("<tr><td colspan = ""3"">There were no orders</td></tr>"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
End If
Response.Write("</table>"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
rsEmployee.Close
Set rsEmployee = Nothing
myConn.Close
Set myConn = Nothing
%>
</div>
</table>
</body>
</html>
I want to be able to select which fields the SQL statement will query data from. So the user would choose a few drop down boxes and pass the params directly into the SQL statement. Is this possible? I can't seem to figure it out.
Below is an example of what I have. Basically if I wanted to replace one of the hard coded fields, ie. Employees.[FirstName], with a selection from my criteria.html form of Employees.[FirstName] instead, how would it work?
Thanks for any help!
Derek
ps. sorry if I'm not making things clear.
Criteria.html Form
<html>
<body>
Select criteria:<p>
<form method="post" action="result.asp">
Choose a field to query:
<select name = "field1">
<option selected>Employees.[Title]
<option>Employees.[FirstName]
<option>Employees.[HireDate]
</select><p>
<input type = "submit" value = "Search">
<input type = "reset" value = "Reset Form">
</form>
</body>
</html>
result.asp
<%Option Explicit%>
<!--METADATA TYPE="TypeLib"
FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->
<html>
<head>
<Title>Northwind Customers</Title>
<link rel = "stylesheet" type = "text/css" href = "myStyle.css">
</head>
<body>
<h1 align="center">Northwind Employees</h1>
<div align = "center">
<table border = "1" bordercolor = "navy" cellpadding = "5" cellspacing = "0" bgcolor = "lightyellow">
<!-- Begin ASP code -->
<%
Dim myConn, rsEmployee, strEmployees, fielda
Set myConn = Server.CreateObject("ADODB.Connection"
'Use a DSN to connect to northwind.mdb
myConn.Open "DSN=Northwind","Admin",""
Set rsEmployee = Server.CreateObject("ADODB.Recordset"
'Create the big Select statement
strEmployees = "SELECT Employees.[FirstName], Employees.[HireDate], Employees.[Title] " _
& "FROM Employees " _
& "ORDER BY Employees.[FirstName]"
rsEmployee.Open strEmployees,myConn,adOpenForwardOnly,adLockReadOnly
Dim Fname,Lname,region,hireDate,Title
If not rsEmployee.BOF then
Response.Write("" _
& "<tr bgcolor = ""pink"">" _
& "<td>" _
& "First Name" _
& "</td>" _
& "<td>" _
& "Title" _
& "</td>" _
& "<td>" _
& "Hire Date" _
& "</td>" _
& "</tr>"
Do While Not rsEmployee.EOF
Fname = rsEmployee.Fields("FirstName"
Lname = rsEmployee.Fields("LastName"
hireDate = rsEmployee.Fields("HireDate"
Title = rsEmployee.Fields("Title"
'Output content data from fields Fname, hireDate and Title
Response.Write("" _
& "<tr>" _
& "<td>" _
& Lname & ", " & Fname _
& "</td>" _
& "<td>" _
& Title _
& "</td>" _
& "<td>" _
& hireDate _
& "</td>" _
& "</tr>"
rsEmployee.MoveNext
Loop
Else
Response.Write("<tr><td colspan = ""3"">There were no orders</td></tr>"
End If
Response.Write("</table>"
rsEmployee.Close
Set rsEmployee = Nothing
myConn.Close
Set myConn = Nothing
%>
</div>
</table>
</body>
</html>