Results 1 to 2 of 2
  1. #1
    kwlmpa is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Aug 2018
    Posts
    1

    VBA - Random sample size based on user form input

    Good evening,

    I am creating a form with the ability to display a random sample sized based on the user input in a textfield. Eg. User specifies they want 3 samples from a customers table; a random sample of 3 are shown as a query result.



    I am having difficulty determining exactly why my code is failing and fails to produce any results:

    Code:
    Private Sub Command0_Click()
        Dim strSQL As String
         
         strSQL = "SELECT TOP " & Me.RandomNumberInput & " *" _
            & "FROM (SELECT Rnd(CustomerID) " _
            & "AS RandomValue, * " _
            & "FROM tCustomers) " _
            & "AS [%$##@_Alias] " _
            & "ORDER BY [%$##@_Alias].RandomValue;"
         Me.RecordSource = strSQL
    End Sub
    Thanks so much!
    -k

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    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.

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

Similar Threads

  1. Criteria based on user input
    By vincentsp in forum Queries
    Replies: 4
    Last Post: 03-25-2015, 10:46 AM
  2. Replies: 1
    Last Post: 11-04-2014, 12:07 PM
  3. A query based on user input in form
    By drhassan in forum Queries
    Replies: 17
    Last Post: 01-20-2014, 06:00 PM
  4. Replies: 3
    Last Post: 03-11-2013, 05:11 PM
  5. Criteria based on user input
    By Alsail77 in forum Queries
    Replies: 5
    Last Post: 08-16-2012, 02:19 PM

Tags for this Thread

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