Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to move through records with button

Status
Not open for further replies.

cazeno

Technical User
Jun 30, 2000
23
0
0
DE
have a question
how to i move through records with buttons....i tried several ways but none of them works.
here is the code i wrote so far for one of the documents.
if i click on a button nothing happens

<%@LANGUAGE=&quot;VBScript&quot;%>
<!-- #INCLUDE VIRTUAL=&quot;adovbs.inc&quot; -->

<html>
<head>
<title>products</title>
<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>
<%
dim SQLQuery
If Not IsEmpty(Request.Form(&quot;MoveAction&quot;)) Then
strAction = Request.Form(&quot;MoveAction&quot;)
varPosition = Request.Form(&quot;Position&quot;)

set myConnection = Server.CreateObject(&quot;ADODB.Connection&quot;)
myConnection.Open &quot;DSN=ph;UID=sa&quot;
set rec = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rec.ActiveConnection = myConnection
rec.CursorType = adOpenDynamic
rec.CursorLocation = adUseClient
rec.LockType = adLockOptimistic
SQLQuery = &quot;select prod_id,descr from prod&quot;
rec.Open SQLQuery, myConnection

rec.MoveFirst
rec.AbsolutePosition = varPosition

Select Case strAction

Case &quot;MoveNext&quot;
rec.MoveNext
If rec.EOF Then
rec.MoveLast
strMessage = &quot;Can't move beyond the last record.&quot;
End If

Case &quot;MovePrev&quot;
rec.MovePrevious
If rec.BOF Then
rec.MoveFirst
strMessage = &quot;Can't move beyond the first record.&quot;
End If

Case &quot;MoveLast&quot;
rec.MoveLast

Case &quot;MoveFirst&quot;
rec.MoveFirst
End Select
End If

%>
<form method=&quot;post&quot; action=&quot;prod.asp&quot;>
<table width=&quot;35%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<tr>
<td>prod_id</td>
<td>
<input type=&quot;text&quot; name=&quot;prodtext&quot; value=&quot;<%=rec.fields(0)%>&quot; maxlength=&quot;500&quot; size=&quot;100&quot;>
</td>
</tr>
<tr>
<td>descr[iption]</td>
<td>
<input type=&quot;text&quot; name=&quot;descrtext&quot; value=&quot;<%=rec.fields(1)%>&quot; size=&quot;100&quot; maxlength=&quot;500&quot;>
</td>
</tr>
</table>
<table width=&quot;14%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; height=&quot;52&quot;>
<tr>
<td width=&quot;9%&quot;>
<input type=Button name=&quot;cmLast&quot; value=&quot;&lt;&lt;&quot;>
</td>
<td width=&quot;10%&quot;>
<input type=Button name=&quot;cmdPrev&quot; value=&quot;&lt;&quot;>
</td>
<td width=&quot;11%&quot;>
<input type=Button name=&quot;cmdNext&quot; value=&quot;&gt;&quot;>
</td>
<td width=&quot;70%&quot;>
<input type=Button name=&quot;cmdFirst&quot; value=&quot;&gt;&gt;&quot;>
</td>
</tr>
<tr>
<td width=&quot;9%&quot;>&nbsp;</td>
<td width=&quot;10%&quot;>&nbsp;</td>
<td width=&quot;11%&quot;>&nbsp;</td>
<td width=&quot;70%&quot;>&nbsp;</td>
</tr>
</table>
<p>&nbsp;</p>
</form>
<p>&nbsp;</p>
<Form Method=Post
Action=&quot;<%=Request.ServerVariables(&quot;SCRIPT_NAME&quot;)%>&quot;
Name=&quot;form_a&quot;>
<Input Type=&quot;Hidden&quot; Size=&quot;4&quot; Name=&quot;MoveAction&quot; Value=&quot;Move&quot;>
<Input Type=&quot;Hidden&quot; Size=&quot;4&quot; Name=&quot;Position&quot; Value=&quot;<%= rec.AbsolutePosition %>&quot;>
</Form>
</body>
<script language=&quot;VBScript&quot;>
Sub cmdPrev_OnClick
rec.MovePrevious
Document.Form.MoveAction.Value = &quot;MovePrev&quot;
Document.Form.Submit
End Sub

Sub cmdNext_OnClick
rec.MoveNext
Document.form.MoveAction.Value = &quot;MoveNext&quot;
Document.Form.Submit
End Sub

Sub cmdFirst_OnClick
rec.MoveFirst
Document.form.MoveAction.Value = &quot;MoveFirst&quot;
Document.Form.Submit
End Sub

Sub cmdLast_OnClick
rec.MoveLast
Document.form.MoveAction.Value = &quot;MoveLast&quot;
Document.Form.Submit
End Sub
</script>
<html>


dont have no idea and nobody to ask for here were im working so....
caz [sig][/sig]
 
I think the probelm stems from switching from Server side scripting to client side scripting

such as:

<script language=&quot;VBScript&quot;>
Sub cmdPrev_OnClick
rec.MovePrevious
Document.Form.MoveAction.Value = &quot;MovePrev&quot;
Document.Form.Submit
End Sub

When you click the command button you are processing a client side script but the recordset is on the server.

<%@LANGUAGE=&quot;VBScript&quot;%>
set rec = Server.CreateObject(&quot;ADODB.Recordset&quot;)


Not sure how to fix it yet.

[sig]<p>DougP, MCP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top