Results 1 to 5 of 5
  1. #1
    cybermonkey is offline Novice
    Windows 10 Office 365
    Join Date
    Jan 2021
    Posts
    16

    Select Random Record

    Hello, I need some assistance. I have a table that only had two headers, ID and QUOTE.
    I want to select a random record and have the QUOTE field be assigned to an already defined variable to be displayed on a box (that part I have, I just need help getting the random record selected).

    When using the following code, I get an error that states "Run-Time error '3464': Data Type mismatch in criteria expression"





    Dim QoDNUM As Integer
    Dim DailyQuote As String
    Dim QNUM As Integer

    'QoDNUM = DCount("*", "QoD")
    'QNUM = Int((QoDNUM - 1 + 1) * Rnd + 1)
    'DailyQuote = DLookup("[Quote]", "QoD", "[ID] = '" & QNUM & "'")





    QNUM is set as an integer and the ID field is a number....so I am sort of at a loss on this one.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    ID and QNUM are number types - remove the apostrophe delimiters as they are used only for text fields.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    No delimiter for a numeric field:

    DailyQuote = DLookup("[Quote]", "QoD", "[ID] = " & QNUM)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    cybermonkey is offline Novice
    Windows 10 Office 365
    Join Date
    Jan 2021
    Posts
    16
    OMG, I can't believe I missed that. All the code like that in this project are all text fields. URGH, it's the simplest mistakes that get people usually LOL

  5. #5
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Suggest you add the line Randomize before the Rnd function line...otherwise you may find yourself getting the same values over & over again
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 19
    Last Post: 04-09-2018, 05:56 PM
  2. Replies: 7
    Last Post: 02-20-2014, 02:34 PM
  3. Replies: 0
    Last Post: 11-30-2010, 12:51 PM
  4. Select Random Records Based on Conditions
    By access123 in forum Queries
    Replies: 1
    Last Post: 10-27-2010, 10:25 AM
  5. random record
    By wasim_sono in forum Programming
    Replies: 1
    Last Post: 02-06-2008, 02:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums