Forum Moderators: open

Message Too Old, No Replies

Access,VBScript, and ASP

         

BrainFry

3:13 pm on Aug 11, 2004 (gmt 0)

10+ Year Member



Hello all,

I have a question on how to create links dynamically from an access db and post them on a page so the links are created automatically.

I have users search for policies based on key words, then the policy names are displayed. I can make them into links, but what I can't quite get is how to make them into links to the different policies without having to code every link to every page. I think that defeats the purpose. I am trying the 'hyperlink' setting in access, but I'm new at this.

I hope my description is understandable!

Thanks All!

Krapulator

12:07 am on Aug 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Add a column to your access table called "url" and place the correct url to the relevant sections in each row.

Then when you write your page with asp, do something like:

<a href="<%=rs("url")%>"><%=rs("policy_name")%></a>

BrainFry

3:59 pm on Aug 12, 2004 (gmt 0)

10+ Year Member



Thanks for replying Krapulator,

I was trying this:

Repsonse.Write "<a href='<%objRec("Link")%>'"

and every variation I could think of and I am still having problems. I also tried your
solution and I have a question on syntax. The '=rs' in your post is something I have not seen before, but I am new at this still. Anyway, I tried both ways and I'm still missing something!

Thanks again for all your help

BrainFry

5:51 pm on Aug 12, 2004 (gmt 0)

10+ Year Member



Ooops, I mistyped:
Should be

Repsonse.Write "<a href='<%objRec("Link")%>'>"

mattglet

2:26 pm on Aug 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<%=objRec("link")%> is shorthand for:

<%Response.Write objRec("link")%>

It's very common practice to use "<%=" when writing out results.

Please post your relavent code (connection string, recordset object, loop, etc. but please no URLs) and we can get you off the ground.

BrainFry

2:58 pm on Aug 13, 2004 (gmt 0)

10+ Year Member



<% t = Request.Form("n") %>
<% a = Request.Form("search1") %>

<% If a = "d" Then %>
<%
Dim objRec
Set objRec = Server.CreateObject("ADODB.Recordset")
objRec.Open "SELECT * FROM Policy WHERE PolName LIKE '" & t & "%'", "dsn=doctest"
Do While Not objRec.EOF
countup = countup + 1
objRec.MoveNext
Loop
If countup > 0 Then
Response.Write "<b>There have been " & countup & " matches.</b><p>"
objRec.MoveFirst
Do While Not objRec.EOF
Response.Write "<a href='<"%objRec("Link")%">'>" & objRec("PolName") & "</a>"
Response.Write "<b><i>" & objRec("PolId") & " " & objRec("PolDesc") & "<br /></i>"
objRec.MoveNext
Response.Write "<br /><br />"
Loop
Else
Response.Write "Sorry, no policies found!<p>"
End If
objRec.Close
Set objRec = Nothing%>
<% End If %>

Thanks for helping out!

I've been reading up on this, but it seems there are about 1000 ways to do the same thing and I can't tell which one pertains to my situation. I suspect my SELECT statement is not entirely right for what I am trying to do.

mattglet

3:06 pm on Aug 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this:

If countup > 0 Then
Response.Write "<b>There have been " & countup & " matches.</b><p>"
objRec.MoveFirst
Do While Not objRec.EOF
Response.Write "<a href=" & objRec("Link") & ">" & objRec("PolName") & "</a>"
Response.Write "<b><i>" & objRec("PolId") & " " & objRec("PolDesc") & "<br /></i>"
objRec.MoveNext
Response.Write "<br /><br />"
Loop
Else
Response.Write "Sorry, no policies found!<p>"
End If

Please post any errors you get.

lty83

3:23 pm on Aug 13, 2004 (gmt 0)

10+ Year Member



if your policies data is in your database simply pull the data from a sql statement and make your code like this

<%
YOUR SQL SEARCH CODE GOES HERE
set rs=conn.execute(sql)
while not rs.eof
<a href = "http://yourwebaddress.com/policies.asp?id=<%=rs("yourUniqueRecordID")"><%= rs("policyName") %></a> <br>
<%
rs.movenext
wend
%>

the above will loop through your policies displaying the relevant ones and linking them to a generic policy page which you can then do this on that generic policy page....

CODE ON POLICY DISPLAY PAGE

<% policyID = request.querystring("id")
sql = "select * from policyTableName where yourUniqueRecordID = " & policyID
set conn=server.createobject("adodb.connection")
set rs=conn.execute(sql)
%>

then simply code in the fields on the page to display that policy to the user

BrainFry

5:35 pm on Aug 13, 2004 (gmt 0)

10+ Year Member



Thanks to Krapulator, Mattglet, and lty83!

The winner is... Mattglet!

Thanks a billion. It worked like a charm.
A few wrong keystrokes can kill you I guess...

Thanks again for everybody's help.