Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    MsAxes is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Hello again - apologies if I need to start another thread. Its the same question though.

    Attached you will find a db named Rand by ID that returns random records based on the count of IDs, it works perfect thanks to June7. The 2nd db named Rand by State has the same idea behind it, return random records but it's based on the State field instead of the ID field.

    I made changes to the VBA to look at the 'State' field instead of 'ID' in the 'Values' table but when I run the code I get a "Run-time error '3061': Too few parameters. Expected 1."

    I read online that can be because the field does not exist or it's misspelled which is not the case. I couldn't find anything online that could help me solve this so I decided to repost.
    Attached Files Attached Files

  2. #17
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    The Great Land
    That error is because State is a text field so criteria requires apostrophe delimiters.

    However, now there will be another error because Rnd() requires numeric input. So still need to use ID for input.

    Set rs2 = CurrentDb.OpenRecordset("SELECT * FROM [Values] WHERE State='" & rs1!State & "' ORDER BY Rnd([ID]);")
    How to attach file: To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #18
    MsAxes is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2021
    Thank you - I was reading about the differences between text and numeric fields but I couldn't figure out where they went - ha.

    Thanks again

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 05-25-2017, 08:50 AM
  2. Replies: 9
    Last Post: 08-19-2014, 12:41 PM
  3. Return Random Records
    By cbrsix in forum Programming
    Replies: 1
    Last Post: 01-11-2013, 06:13 PM
  4. Return field value based on the same table
    By snoopy2003 in forum Queries
    Replies: 2
    Last Post: 03-05-2011, 02:45 AM
  5. Select Random Records Based on Conditions
    By access123 in forum Queries
    Replies: 1
    Last Post: 10-27-2010, 10:25 AM

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