Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Access Database & NEWID()

  • 06-11-2003 11:49PM
    #1
    Closed Accounts Posts: 40


    I am working on this project and I want to display a random recordset, but it does not seem towork with Access at all.

    I have it workin in SQL 2000 database but access is more complicated.

    Can anyone help?

    <%
    Dim rsSpecials
    Dim rsSpecials_numRows

    Set rsSpecials = Server.CreateObject("ADODB.Recordset")
    rsSpecials.ActiveConnection = MM_conn_STRING
    rsSpecials.Source = "SELECT P_Name, P_OnSpecial, P_OnSpecialPrice, P_SmallPicture, P_ID, NEWID() AS P_ID1 FROM Products WHERE P_OnSpecial=yes ORDER BY P_ID1"
    rsSpecials.CursorType = 0
    rsSpecials.CursorLocation = 2
    rsSpecials.LockType = 1
    rsSpecials.Open()

    rsSpecials_numRows = 0
    %>

    The NEWID() part is the problem.

    I tried RAND() but.......


Comments

  • Closed Accounts Posts: 40 lucian


    For everybody who ever gets into the same position I was in, I sorted out like this:

    <%
    Const adCmdText = &H0001

    Dim rsNewProducts
    Dim rsNewProducts_numRows

    Set rsNewProducts = Server.CreateObject("ADODB.Recordset")
    rsNewProducts.ActiveConnection = MM_conn_STRING
    rsNewProducts.Source = "SELECT * FROM NewProducts ORDER BY P_DATEADDED"
    rsNewProducts.CursorType = 0
    rsNewProducts.CursorLocation = 3
    rsNewProducts.LockType = 1
    rsNewProducts.Open()

    rsNewProducts_numRows = 0

    Dim intRnd
    Randomize Timer
    intRnd = (Int(RND * rsNewProducts.RecordCount))

    ' Now moving the cursor to random record number
    rsNewProducts.Move intRnd
    %>


Advertisement