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 do I bring up the last record for deletion?

Status
Not open for further replies.

tazzer

Technical User
May 3, 2001
11
0
0
GB
Hi,

I've created a form where records are added and deleted from an Access database. The deletion code currently displays all the records and allows the user to choose any to delete. However I want only the last record entered to be available for deletion.

The code is as follows:

<%dim conn, rs
set conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
conn.Open(&quot;DSN=Logger&quot;)
set rs = conn.execute(&quot;Select * From tblMail&quot;)
'put in the table size and headings
response.write &quot;<TABLE BORDER=2 cellpadding=6>&quot;
response.write &quot;<TR><TH>Sender</TH><TH>Date</TH><TH>Month</TH>&quot;
response.write &quot;<TH>Description</TH><TH>Recipient</TH><TR>&quot;
Do until rs.EOF
response.write &quot;<TR>&quot;
response.write &quot;<TD><A HREF='deletecontact.asp?intID=&quot;
response.write server.urlencode(rs(&quot;intID&quot;)) & &quot;'>&quot;
response.write rs(&quot;strSender&quot;) & &quot;</TD>&quot;
response.write &quot;<TD>&quot; & rs(&quot;datDate&quot;) & &quot;</TD>&quot;
response.write &quot;<TD>&quot; & rs(&quot;datMonth&quot;) & &quot;</TD>&quot;
response.write &quot;<TD>&quot; & rs(&quot;strDescription&quot;) & &quot;</TD>&quot;
response.write &quot;<TD>&quot; & rs(&quot;strRecipient&quot;) & &quot;</TD>&quot;
response.write &quot;</TR>&quot;
rs.movenext
Loop
response.write &quot;</TABLE>&quot;
rs.close
conn.close
%>

Can anyone help with this?

:-(

Tazzer

 
I'm not sure I know what your wanting but a couple of ways could work:
if you just want to show the record which can be deleted use the rs.movelast and get rid of the rest of the loop. or if you want the entire list but only be able to delete the last record you can test for eof with a if... statement and write the delete link to you delete function.(this will not if you use and order by in your sql statement). you could also create a loop to go through all the records and find the record with the highest id number if this is an autonumber fields with something like this.
dim id
id = 0
do until rs.eof
if rs.(&quot;id&quot;) > id then
id = rs.(&quot;id&quot;)
end if
loop
Then use the id to determine which record to delete. I hope this helps
 

Thanks BlastRadius,

Took your advice and got rid of the loop; the following code worked for me:

<%dim conn, rs
set conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
conn.Open(&quot;DSN=Logger&quot;)
set rs = conn.execute(&quot;Select * From tblMail Order by intID Desc&quot;)
'put in the table size and headings
response.write &quot;<TABLE BORDER=2 cellpadding=6>&quot;
response.write &quot;<TR><TH>Sender</TH><TH>Date</TH><TH>Month</TH>&quot;
response.write &quot;<TH>Description</TH><TH>Recipient</TH><TR>&quot;
response.write &quot;<TR>&quot;
response.write &quot;<TD><A HREF='deletecontact.asp?intID=&quot;
response.write server.urlencode(rs(&quot;intID&quot;)) & &quot;'>&quot;
response.write rs(&quot;strSender&quot;) & &quot;</TD>&quot;
response.write &quot;<TD>&quot; & rs(&quot;datDate&quot;) & &quot;</TD>&quot;
response.write &quot;<TD>&quot; & rs(&quot;datMonth&quot;) & &quot;</TD>&quot;
response.write &quot;<TD>&quot; & rs(&quot;strDescription&quot;) & &quot;</TD>&quot;
response.write &quot;<TD>&quot; & rs(&quot;strRecipient&quot;) & &quot;</TD>&quot;
response.write &quot;</TR>&quot;
response.write &quot;</TABLE>&quot;
rs.close
conn.close
%>

Thanks,

Tazzer
 
Tazzer,

You could order your SELECT statement first and then use:

rs.movelast

to move to the last record.

Fengshui_1988
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top