|
-
Jan 27th, 2005, 04:14 PM
#1
Thread Starter
Fanatic Member
Pass a variable from a web form to Query in Access 2000
I have a text box on my asp page. Is it possible to pass that value to a query in Access and run the report?
-
Jan 27th, 2005, 04:21 PM
#2
Addicted Member
Re: Pass a variable from a web form to Query in Access 2000
Hey John,
That's a pretty easy one! The best way to do it is to have the first part of your search string hardcoded into the page and then attach the search criteria to the end of it using a form. So, an example might look something like this:
HTML Code:
Page 1:
<form name='Query' method='get'>
Enter your criteria: <input name='criteria' type='text'>
<input type='submit' value='Go'>
</form>
Page 2:
Dim strCriteria
Dim rs
strCriteria = Request.Querystring("Criteria") 'This gets the value from the text box.
'Open connection to database
rs.Open "SELECT * FROM table1 WHERE something = '" & strCriteria & "'", connectionstring
Let me know if you need more help
Jim P.
"The Force will be with you, always."
--Ben Kenobi--
-
Jan 27th, 2005, 11:42 PM
#3
Thread Starter
Fanatic Member
Re: Pass a variable from a web form to Query in Access 2000
Thanks for your reply but not what I was looking for. I have an asp page with a text box. When I click the submit button I want to pass that value into the Access database query and display the report from Access into the browser.
I am able to get the text box value into the query but unable to open a report in Access from my asp page.
Here is my code to pass a value from a asp page to a query within Access:
YOUR HELP IS GREATLY APPRECIATED..
Dim cmd, rs, connect
Const adCmdStoredProc = &H0004
Const adParamInput = &H0001
Const adVarChar = 200
Set cmd = Server.CreateObject ("ADODB.Command")
connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("courses.mdb") & ";Persist Security Info=False"
cmd.ActiveConnection = connect
cmd.CommandText = "q_Names"
cmd.CommandType = adCmdStoredProc
cmd.Parameters.Append cmd.CreateParameter ("@fname",adVarChar,adParamInput ,10,"John")
Set rs = Server.CreateObject ("ADODB.Recordset")
Set rs = cmd.Execute
do while not rs.EOF
Response.Write rs("firstName") & " " & rs("lastName") & "<br>"
rs.MoveNext
loop
'DoCmd.OpenReport
rs.Close
Set rs = nothing
set cmd = nothing
-
Jan 28th, 2005, 12:12 AM
#4
Re: Pass a variable from a web form to Query in Access 2000
JPiller's answer is correct.
In the line
Code:
cmd.Parameters.Append cmd.CreateParameter ("@fname",adVarChar,adParamInput ,10,"John")
Instead of "John", you would put the variable strCriteria, which in turn you get from the Request.QueryString() line.
-
Jan 28th, 2005, 05:59 AM
#5
Thread Starter
Fanatic Member
Re: Pass a variable from a web form to Query in Access 2000
I want to open an Access Report with criteria...
-
Jan 28th, 2005, 09:10 AM
#6
Addicted Member
Re: Pass a variable from a web form to Query in Access 2000
Okay, is the access report saved in the database? If so, check out this link that tells how to view a saved access report from within an ASP page:
http://www.4guysfromrolla.com/webtech/042600-1.shtml
Hope this is more along the lines of what you're looking for.
Jim P.
"The Force will be with you, always."
--Ben Kenobi--
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|