Problem with an .asp page displaying data based on a form field value.

Discussion in 'ASP General' started by Brave, Feb 14, 2007.

  1. Brave

    Brave Guest

    I'm hoping someone can help me with a small issue.

    I have an asp page that displays informaton from an Access database.
    I want to create a form that allows users to display only data that
    matches their search criteria.

    I have made many forms like this in Front Page with the Database
    results wizard, but I want to manually code it.

    Here is the code I use to display the data from a database.

    <%
    Set Conn = Server.CreateObject("ADODB.Connection")
    Conn.Open "driver={Microsoft Access Driver (*.mdb)};;DBQ=\\****\****
    \DatabaseName.mdb;"
    mySQL="SELECT * FROM DatabaseTableName WHERE (TableFieldName =
    'FieldValue') ORDER BY TableFieldName ASC"
    Set RS = Conn.Execute(mySQL)
    If RS.EOF and RS.BOF Then
    Response.Write("<font face=""verdana"" size=""2""><p>No records
    returned.</p>")

    Else

    Response.Write "<table><tr>"
    Response.Write "<td><b>Table Field Name</b></td>"
    Response.Write "</tr>"

    Do While Not RS.EOF

    Response.Write "<tr>"
    Response.Write "<td>"&RS("FieldValue")&"</td>"
    Response.Write "</tr>"

    RS.MoveNext
    Loop
    End If

    Response.Write "</table>"

    RS.Close
    Conn.Close
    Set RS = Nothing
    Set Conn = Nothing
    %>

    What I want to do is add a form like the one below that user can use
    to determine the "field value" that is displayed.

    <p><form METHOD="POST" ACTION="WebPageName.asp"><input
    NAME="FormField" VALUE="<%=Request("FormFieldValue")%>"
    size="24">&nbsp;<input TYPE="submit" value="Search!"></form></p>

    So if they type in "Smith" they get all entries that have a field
    value of Smith

    I'm not sure how to write the query so it looks at the form for the
    value it uses to display information.

    Any code examples would help me a great deal as I seem to be close,
    but I cannot "connect" to two elements.

    Thanks for taking the time to read all of this, and for any assiatance
    you can offer.
    Brave, Feb 14, 2007
    #1
    1. Advertising

  2. Brave

    Patrick Guest

    I think you want something like this:

    mySQL="SELECT * FROM DatabaseTableName WHERE (TableFieldName='" &
    Request.Form("FieldValue") & "') ORDER BY TableFieldName ASC"

    It's a single quote followed by doublequotes after TableFieldName=, and
    doublequotes followed by a single quote before the ORDER BY


    "Brave" <> wrote in message
    news:...
    > I'm hoping someone can help me with a small issue.
    >
    > I have an asp page that displays informaton from an Access database.
    > I want to create a form that allows users to display only data that
    > matches their search criteria.
    >
    > I have made many forms like this in Front Page with the Database
    > results wizard, but I want to manually code it.
    >
    > Here is the code I use to display the data from a database.
    >
    > <%
    > Set Conn = Server.CreateObject("ADODB.Connection")
    > Conn.Open "driver={Microsoft Access Driver (*.mdb)};;DBQ=\\****\****
    > \DatabaseName.mdb;"
    > mySQL="SELECT * FROM DatabaseTableName WHERE (TableFieldName =
    > 'FieldValue') ORDER BY TableFieldName ASC"
    > Set RS = Conn.Execute(mySQL)
    > If RS.EOF and RS.BOF Then
    > Response.Write("<font face=""verdana"" size=""2""><p>No records
    > returned.</p>")
    >
    > Else
    >
    > Response.Write "<table><tr>"
    > Response.Write "<td><b>Table Field Name</b></td>"
    > Response.Write "</tr>"
    >
    > Do While Not RS.EOF
    >
    > Response.Write "<tr>"
    > Response.Write "<td>"&RS("FieldValue")&"</td>"
    > Response.Write "</tr>"
    >
    > RS.MoveNext
    > Loop
    > End If
    >
    > Response.Write "</table>"
    >
    > RS.Close
    > Conn.Close
    > Set RS = Nothing
    > Set Conn = Nothing
    > %>
    >
    > What I want to do is add a form like the one below that user can use
    > to determine the "field value" that is displayed.
    >
    > <p><form METHOD="POST" ACTION="WebPageName.asp"><input
    > NAME="FormField" VALUE="<%=Request("FormFieldValue")%>"
    > size="24">&nbsp;<input TYPE="submit" value="Search!"></form></p>
    >
    > So if they type in "Smith" they get all entries that have a field
    > value of Smith
    >
    > I'm not sure how to write the query so it looks at the form for the
    > value it uses to display information.
    >
    > Any code examples would help me a great deal as I seem to be close,
    > but I cannot "connect" to two elements.
    >
    > Thanks for taking the time to read all of this, and for any assiatance
    > you can offer.
    >
    Patrick, Feb 16, 2007
    #2
    1. Advertising

  3. Brave

    Brave Guest

    On Feb 16, 1:33 am, "Patrick" <> wrote:
    > I think you want something like this:
    >
    > mySQL="SELECT * FROM DatabaseTableName WHERE (TableFieldName='" &
    > Request.Form("FieldValue") & "') ORDER BY TableFieldName ASC"
    >
    > It's a single quote followed by doublequotes after TableFieldName=, and
    > doublequotes followed by a single quote before the ORDER BY
    >
    > "Brave" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > I'm hoping someone can help me with a small issue.

    >
    > > I have an asp page that displays informaton from an Access database.
    > > I want to create a form that allows users to display only data that
    > > matches their search criteria.

    >
    > > I have made many forms like this in Front Page with the Database
    > > results wizard, but I want to manually code it.

    >
    > > Here is the code I use to display the data from a database.

    >
    > > <%
    > > Set Conn = Server.CreateObject("ADODB.Connection")
    > > Conn.Open "driver={Microsoft Access Driver (*.mdb)};;DBQ=\\****\****
    > > \DatabaseName.mdb;"
    > > mySQL="SELECT * FROM DatabaseTableName WHERE (TableFieldName =
    > > 'FieldValue') ORDER BY TableFieldName ASC"
    > > Set RS = Conn.Execute(mySQL)
    > > If RS.EOF and RS.BOF Then
    > > Response.Write("<font face=""verdana"" size=""2""><p>No records
    > > returned.</p>")

    >
    > > Else

    >
    > > Response.Write "<table><tr>"
    > > Response.Write "<td><b>Table Field Name</b></td>"
    > > Response.Write "</tr>"

    >
    > > Do While Not RS.EOF

    >
    > > Response.Write "<tr>"
    > > Response.Write "<td>"&RS("FieldValue")&"</td>"
    > > Response.Write "</tr>"

    >
    > > RS.MoveNext
    > > Loop
    > > End If

    >
    > > Response.Write "</table>"

    >
    > > RS.Close
    > > Conn.Close
    > > Set RS = Nothing
    > > Set Conn = Nothing
    > > %>

    >
    > > What I want to do is add a form like the one below that user can use
    > > to determine the "field value" that is displayed.

    >
    > > <p><form METHOD="POST" ACTION="WebPageName.asp"><input
    > > NAME="FormField" VALUE="<%=Request("FormFieldValue")%>"
    > > size="24">&nbsp;<input TYPE="submit" value="Search!"></form></p>

    >
    > > So if they type in "Smith" they get all entries that have a field
    > > value of Smith

    >
    > > I'm not sure how to write the query so it looks at the form for the
    > > value it uses to display information.

    >
    > > Any code examples would help me a great deal as I seem to be close,
    > > but I cannot "connect" to two elements.

    >
    > > Thanks for taking the time to read all of this, and for any assiatance
    > > you can offer.- Hide quoted text -

    >
    > - Show quoted text -


    Thanks so much. I will give it a try.
    Brave, Feb 16, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Emmanuel
    Replies:
    1
    Views:
    667
    Karl Seguin
    Nov 22, 2005
  2. GavMc
    Replies:
    4
    Views:
    322
    Evertjan.
    Sep 22, 2005
  3. Brett_A
    Replies:
    8
    Views:
    184
    Bob Barrows [MVP]
    Apr 19, 2008
  4. jochen scheire

    Calculate field based on another field in form

    jochen scheire, Apr 21, 2004, in forum: Javascript
    Replies:
    6
    Views:
    185
    Mick White
    Apr 22, 2004
  5. jr
    Replies:
    3
    Views:
    414
Loading...

Share This Page