ASP question

  • Thread starter Thread starter Matt Shudy
  • Start date Start date
M

Matt Shudy

Hi,

I am just trying to display a record from a database. I
am using
Response.Write objBU("2003")
and I want to add a Request.Form("Year") to it...

What would be the correct code for this?

Response.Write objBU(Request.Form("Year"))
I know the above doesn't work, just wanted to show what I
want to do...

Thanks,

Matt Shudy
 
Hey,

The 2003 is the column name in my db. I would like the
page so the user chooses from a select number of years to
get the db results... For example, the user enters their
budgets (objBU), then they want to see the results (other
info is also reported...), so they choose 2004, I need the
Response.Write obj("2003") to now include the Request.Form
("Year") command. Did you mean for me to try
Response.Write objBU(Response.Write Request.Form("Year"))?

I tried that, and got the following
Microsoft VBScript compilation error '800a03ee'

Expected ')'

/enveng/bowlingcharts/bcview.asp, line 278

Response.Write "<TD rowspan=2>" & objBU("Response.Write
Request.Form("Year")") & "</TD>"
--------------^

Thanks,

Matt Shudy
 
I also tried it without the ""'s around the Response.Write
Request.Form("Year") and got the same error message, but
the arrow pointing to the R on Response.Write

Matt Shudy
 
Matt,

I'm confused. Are you trying to do a response.write on a value that's
inputted from a form or a value coming from your database? If objBU is your
recordset then when you do Response.Write it would be:

Response.Write objBU("FIELDNAME")

If you are trying to get the value that was typed into a form field it would
be:

Response.Write Request.Form("FORMFIELDNAME")

If you want BOTH then it would be:

Response.Write objBU("FIELDNAME") & Request.Form("FORMFIELDNAME") or:

Response.Write objBU("FIELDNAME") & " " & Request.Form("FORMFIELDNAME") -
puts a space between them.
 
Year is a reserved word, change the fieldname to something else in the
database, etc.

--

==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, Forums, WebCircle,
MS KB Quick Links, etc.
==============================================
 
Hey,

Sorry to be confusing...

The form field is the record set field name. I put the
year 2003 in to test the page i made, but obvisouly it has
to change now. So instead of hardcoding it ( objBU
("2004") ), i would like to make it so the user chooses
the year in the form then hits submit and gets the results
on the next page. So i want a page that would display a
recordset (objBU) based on the user's selection of the
year.

Thanks,

Matt Shudy
 
Hi Matt. Ok, I'm still not 100% sure what you mean but if you want to show
what's in the database in the form field and then see that result on the
next page you'd do this:

Page1:
<input type = "text" name="Year" value="<%=objBU(FIELDNAME")%>

Page2:

Response.Write Request.Form("Year")
 
Hi,

The year field, is only used by the form, the db columns
are named 2002, 2003, 2004, etc.

Matt Shudy
 
Hey,

Sorry no url, this is published on an intranet site.

I'll try to explain it better.

Page one (the form page)
there is a form on this page with two drop down boxes, one
is for the plant, and the other is for the year. the two
values are submitted to another page, called view.asp.

Page two (the view page)
On this page there is a table that displays a bunch of
different things, one being the budgets for this year and
last year. The budget recordset is objBU. Right now
there is a line of code (in a while not objBU.EOF loop)
that is response.write objBU("2003"). That displays 8
values (one value each time it goes through the loop). I
will make a new database column named 2004. The table
would be correct if i were to hard code 2004 into it, objBU
("2004") and objBU("2003") (the 2003 is in there now for
the past year, i had 2002 hard coded in last year).
However the table would not be correct if the user wants
to view the table from last year, because the budgets will
be from 2004 and 2003 instead of 2003 and 2002. The page
needs to have the budgets displayed based on the year
chosen on the previous form page. ex, if the user chooses
the year 2003, the view.asp page will display the budgets
for year 2003 and also show the budgets from 2002, ex, if
the user chooses year 2004, then the view.asp page will
display budgets from year 2004 and also show (just for
comparison) the budgets from 2003. So what i need is a
way to insert the year value from the form into the
response.write objBU("Requested From Form") code.

Does this help at all? I can try to explain it again
otherwise..

Thanks,

Matt Shudy
 
Hey,

Not sure if you checked my above reply...

The word Year is only used in the form. The db column
names are the actual years ex, 2003, 2004.

Matt Shudy
 
Hi Mattt,
for anything in asp you can either enter a string literal (something in
quotes) or a variable or a form/query string value. For example (where oRs
is your recordset) you could do
<%
response.write oRs("fieldname")
%>
or
<%
strTemp = "fieldname"
response.write oRs(strTemp)
%>
or
<%
response.write oRs(request.form("YourFormField"))
%>
so I think the answer to your question is
<%
response.write objBU(request.form("year"))
%>
 
sorry - answer should be
<%
strTemp = request.form("year")
response.write objBU(strTemp)
%>

Jon
 
Hey,

I tried that and got an error... I think the problem with
that is that there are no "'s around the field name then.
If the request.form would work the code would then read
response.write oRs(2004). Is there a way to make it so it
would read response.write oRs("2004"), using a request.form
("year") to get the 2004 year?

Thanks,

Matt Shudy
 
Matt,

The way you should be doing this is to base you SQL statement on the value
that's passed from the form. for example:

SQL = "SELECT * FROM Table WHERE Year = '" & Request.Form & "' "

It appears that you want to dynamically populate the recordset field based
on the form value like this:

strFieldName = Trim(Request.Form("Year"))

Response.Write objBU(strFieldName)
 
Matt, you shouldn't need the double quotes. I just tested it locally to be
sure and it works fine:

strFieldName = Trim(Request.Form("Year"))

Response.Write objBU(strFieldName)
 
Hi,

When i try that, i get the error, "Item cannot be found in
the collection corresponding to the requested name or
ordinal".

Matt Shudy
 
Matt, that error generally means that the field name you're trying to
retrieve doesn't exist. To see if you're getting the right value from the
form you should do a Response.Write Request.Form("Year"). You should also
do a Trim on the value to remove any spaces.
 
Is strFieldName equal to the value of Request.Form? I ran this locally and
it's working fine for me. Try this:

strFieldName = "2003"
Response.Write objBU(strFieldName)

and tell me if that works.
 
Back
Top