Hallo, jag undrar hur det går till om man vill slumpa fram en post ur denna kodrad Testa RecordCount är beroende av cursor. För att det skall funka bör man ha antingen en cursor location lokal eller statisk cursor, har jag för mig. Tackar för hjälpen, det blev denne varianten. hmmm... varför loopen?  Testade din variant men där får jag bara fram post MobilID 1, kanske nån liten fnurra bara. Tackar ändå för engagemanget Om det inte rör sig om så många poster i excel-filen så kanske detta vara en enklare och smidigare lösning:Slumpa RS
    
    
<code>
<%
    strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source = " & Server.MapPath("MobilNr.xls") & ";" & _
    "Extended Properties=""Excel 8.0;HDR=Yes;"";"
    FilePath = Server.MapPath("MobilNr")
    Set Conn = Server.CreateObject("ADODB.Connection") 
        Conn.Open strConn 
            Set RS = Conn.Execute("SELECT MobilNr FROM [MobilNr$]")
                Do Until RS.EOF
                    Response.Write RS("MobilNr")
                RS.MoveNext
	Loop 
            Set RS = Nothing 
        Conn.Close 
    Set Conn = Nothing 
%> 
</code>Sv: Slumpa RS
    
    
If Not RS.EOF Then
  Randomize
  RS.Move Int(Rnd*RS.RecordCount)+1
  Response.Write RS("MobilNr")
End If
Funkar inte RecordCount så kan du först läsa in antalet poster med ex "SELECT Count(MobilNr) AS Antal FROM [MobilNr$]"
    Sv:Slumpa RS
    
    
Annars kan man läsa samtliga id till en array. sedan slumpa fram ett ID och hämta posten. Detta innebär ju två databas anrop.Sv: Slumpa RS
    
    
<code>
<%
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
               "Data Source = " & Server.MapPath("MobilNr.xls") & ";" & _
               "Extended Properties=""Excel 8.0;HDR=Yes;"";"
FilePath = Server.MapPath("MobilNr")
    Set Conn = Server.CreateObject("ADODB.Connection") 
        Conn.Open strConn 
            Set RS = Conn.Execute("SELECT Count(MobilID) AS MobilID FROM [MobilNr$]")
                Do Until RS.EOF
                    Randomize
	    i = Int(Rnd * RS("MobilID") + 1)
	    MobilID = i
                RS.MoveNext
	Loop
	Set sRS = Conn.Execute("SELECT * FROM [MobilNr$] Where MobilID =" & MobilID )
	   Response.Write sRS("MobilID") & vbCRLF
	   Response.Write sRS("Namn") & vbCRLF
	   Response.Write sRS("MobilNr")
            	Set RS = Nothing
            Set sRS = Nothing 
        Conn.Close 
    Set Conn = Nothing 
%>
</code>
Tackar för hjälpenSv:Slumpa RS
    
    
...och vad händer om du tar bort en rad från Excel-listan och det är just detta MobilID som slumpas fram?
<%
  strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                 "Data Source = " & Server.MapPath("MobilNr.xls") & ";" & _
                 "Extended Properties=""Excel 8.0;HDR=Yes;"";"
  FilePath = Server.MapPath("MobilNr")
  Set Conn = Server.CreateObject("ADODB.Connection") 
  Conn.Open strConn 
  Set RS = Conn.Execute("SELECT Count(MobilID) AS MobilID FROM [MobilNr$]")
  Randomize
  i = Int(Rnd * RS("MobilID") + 1)
  Set sRS = Conn.Execute("SELECT * FROM [MobilNr$]")
  RS.Move i
  Response.Write sRS("MobilID") & vbCRLF
  Response.Write sRS("Namn") & vbCRLF
  Response.Write sRS("MobilNr")
  Set RS = Nothing
  Set sRS = Nothing 
  Conn.Close 
  Set Conn = Nothing 
%>
    Sv: Slumpa RS
    
    
MVH UffeSv:Slumpa RS
    
    
<%@Language="VBScript" CODEPAGE="65001"%>
<!-- METADATA
	TYPE="TypeLib"
	NAME="Microsoft ActiveX Data Objects 2.6 Library"
	UUID="{00000206-0000-0010-8000-00AA006D2EA4}"
	VERSION="2.6" -->
<%Option Explicit%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
</head>
<body>
<%
Dim rs
Dim con
Dim strCon
Dim FilePath
	FilePath = Server.MapPath("MobilNr.xls")
	strCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
	         "Extended Properties=""Excel 8.0;HDR=Yes;"";" & _
	         "Data Source = " & FilePath & ";" 
	Set con = Server.CreateObject("ADODB.Connection") 
	con.Open strCon
	Set rs = Server.CreateObject("ADODB.Recordset") 
	rs.Open "SELECT *" + vbCrLf + _
	        "FROM [MobilNr$]", con, adOpenStatic, adLockReadOnly 	
	If rs.EOF Then
		Respons.Write "<h3>Inga poster!</h3>"
	Else
		Randomize
		rs.Move int(rs.RecordCount * rnd), adBookmarkFirst
		Response.Write rs("MobilID") & vbCRLF
		Response.Write rs("Namn") & vbCRLF
		Response.Write rs("MobilNr") & vbCRLF
	End If	      
	rs.Close
	Con.Close 
%></body>
</html>