Results 1 to 3 of 3
  1. #1
    lccrews is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Location
    Los Angeles
    Posts
    194

    Is it possible to run a query as many times as instructed from a text box?

    I have a query that appends a row of data based on a complex math problem. This row of data needs to be duplicated on the same table based on a number that is in textbox 1. The reason for duplicating is this is part of a recipe and the ingredient is mixed in stages.

    Is it possible to re-write the code I'm using to run the query as many times as needed?


    Code:
    Private Sub Command513_Click()    
        DoCmd.SetWarnings (WarningsOff)
        DoCmd.OpenQuery "qry_BP40_Gummy_We04_Pt12"
        DoCmd.SetWarnings (WarningsOn)
        DoCmd.RefreshRecord
    End Sub

  2. #2
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    You can either write a loop in vba to do this or more efficiently use a table with a single number field and a Cartesian join.
    Use a table that has as many rows as you are ever going to need. So, if the max number of rows you will ever need to add is 50, then your numbers table would have 50 rows with 1 field containing the numbers from 1 through 50. You add this table to your append query and add criteria that selects rows where the NumberVal is <= whatever your target number is. There is no join line between this table and any other table in the query. (This quoted from another site here https://www.access-programmers.co.uk...d.php?t=297592as it described it so eloquently)

    In the criteria you can either refer to the form you are running this from [Forms]![YourFormName].[YourControlWithTheCountIn] or use [Enter repeats] to make it prompt you. (Not as elegant..)

    This is far more efficient than re-running the same query umpteen times.

  3. #3
    lccrews is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Aug 2017
    Location
    Los Angeles
    Posts
    194
    Thanks Minty!

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

Similar Threads

  1. Replies: 9
    Last Post: 01-23-2017, 08:53 AM
  2. Replies: 2
    Last Post: 11-28-2016, 09:49 PM
  3. Replies: 2
    Last Post: 02-25-2015, 05:02 PM
  4. Replies: 9
    Last Post: 04-25-2014, 12:33 PM
  5. Replies: 3
    Last Post: 02-22-2013, 11:34 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