Re: if statement comparing variable

From: Bob Barrows (reb01501_at_NOyahoo.SPAMcom)
Date: 02/29/04


Date: Sun, 29 Feb 2004 10:54:38 -0500

Michael Haas wrote:
> I'm trying to use a variable of retrieved via request from a form to
> select records.I'm pretty sure I am having a basic syntax error or
> something else basic.
> I retrieve the variable from a prevous form:
> section_id = request("section_id")
>
> I then retrieve some records and run the compare, if i use the actual
> value it works:
> if rsArticles("tbl_articles.section_id") = "1" then

This line is not giving you an error?? Do you have On Error Resume Next in
your code? Comment it out. You will see an error generated by this line. You
cannot refer to a recordset field using the table name like this. You can
only use:

a) the ordinal position of the field in the Fields collection:
    rsArticles(1).value ' refers to second field in collection
b) the column name or column alias
    rsArticles("section_id")

If you have more than one field called "section_id" in the results, then:

1) If both fields contain the same information - Stop writing inefficient
code! Your goal should be to bring as little data across the network as
possible. Using "Select *" defeats that goal. Don't bring the same
information across the network twice!

2) If the fields contain dissimilar information, then you need to assign
aliases to the columns so they will have different names in the recordset:
Select tbl_articles.section_id AS articles_section_id, ...
This will allow you to refer to it as
rsArticles("articles_section_id")

Your following description is unclear, and I suspect the results are being
clouded by the error in your reference to the recordset field.

>
> however if I substitute the variable section_id which equals 1 , it
> fails the compare and moves on to the else:
> if rsArticles("tbl_articles.section_id") = section_id then
>
> if I call the section_id value elsewhere it shows that it is set to 1,
> so I know it's being passed, <%=section_id%> returns 1
>
> What am I missing?

Bob Barrows

-- 
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


Relevant Pages

  • Re: LIST option problems
    ... it's relate to port opening. ... refer alun's post. ... Bernard Cheah ... > but when i type LIST it seems to get stuck, do i have to retrieve the ...
    (microsoft.public.inetserver.iis.ftp)
  • Re: Define Const for Date Format
    ... You can't refer to constants in a package directly. ... You need a function in the package to retrieve ... Senior Oracle DBA ... Prev by Date: ...
    (comp.databases.oracle.misc)
  • RE: Refer to Field Name dynamically
    ... I believe you refer to a recordset field like this: ... "Brad" wrote: ... I've done it on a form with Controls ...
    (microsoft.public.access.modulesdaovba)
  • RE: modify Local area connection property settings
    ... I think you may retrieve such information from a WMI class ... For more information, you may refer to ... Luke ...
    (microsoft.public.scripting.wsh)
  • Re: SELECT MAX(...) returns 0
    ... Yes, I refer rs ... > What's your code look like: how are you referring to the field when you ... > retrieve it from the recordset? ... >> Regards, ...
    (microsoft.public.vb.database.ado)

Loading